2013-03-06 54 views
0
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中無效的網址或端口錯誤?

+1

你爲什麼要在getToken上調用toString?這已經是一個字符串... – Matthieu 2013-03-06 17:56:11

回答

0

你可能想看看URI constructors並使用它們。手動建立是一個不錯的方法。

1

我有同樣的問題。爲了解決這個問題,我不得不編輯位於Moodle的根文件夾中的文件config.php內以下行(/var/www/moodle/config.php在我的情況,在Ubuntu 12.10):

$CFG->wwwroot = 'http://10.0.2.2/moodle'; 

你將不得不使用的IP地址,你的設備將作爲Moodle Web服務器的主機(在仿真器的情況下,主機看在10.0.2.2)。

相關問題