String str1="http://10.0.2.2/moodle";
String str4="admin";
String str5="[email protected]";
try{
String getToken = str1 + "/login/token.php?username=" + str4 + "&password=" + str5 + "&service=moodle_mobile_app";
String inputLine = null;
URL url = new URL(getToken.toString());
System.out.println("Port----------->"+url.getPort());
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((inputLine = in.readLine()) != null) {
System.out.println("test1"+inputLine);
}
in.close();
} catch(Exception e) {
System.out.println(e.toString());
}
}
當我嘗試從localhost moodle course web獲取令牌時,我的端口號爲-1。 我得到這個錯誤「:」無效的網址或端口。對於上面的代碼 請幫我解決這個錯誤。如何修復Android中無效的網址或端口錯誤?
你爲什麼要在getToken上調用toString?這已經是一個字符串... – Matthieu 2013-03-06 17:56:11