Reputation: 1
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.
Upvotes: 0
Views: 2468
Reputation: 183
I have got the same problem. To resolve it I had to edit the following line inside the config.php
file located in the Moodle root folder (/var/www/moodle/config.php
in my case, on Ubuntu 12.10):
$CFG->wwwroot = 'http://10.0.2.2/moodle';
You'll have to use the IP address which your device will see as the host of the Moodle web server (in case of the emulator, the host machine is seen at 10.0.2.2).
Upvotes: 1
Reputation: 636
You may want to look at the URI constructors and use those instead. Building by hand is a bad way to do it.
Upvotes: 0