0
String str1="http://10.0.2.2/moodle";   
String str4="admin";
String str5="S12345s@";

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());
}
}

when i try to get the token from localhost moodle course web and i got port number as -1. I got this error":"Invalid url or port. for above code please help me to fix this error.

4

2 回答 2

1

我有同样的问题。config.php为了解决它,我必须在位于 Moodle 根文件夹中的文件中编辑以下行(/var/www/moodle/config.php在我的例子中,在 Ubuntu 12.10 上):

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

您必须使用您的设备将看到的 IP 地址作为 Moodle 网络服务器的主机(在模拟器的情况下,主机位于 10.0.2.2)。

于 2014-09-04T08:42:59.607 回答
0

您可能想查看URI 构造函数并改用它们。手工建造是一种不好的方法。

于 2013-03-06T18:50:02.367 回答