I use Eclipse and when I try to connect to my servlet using 'normal' Java, it works fine.
But when I paste the same code in my Android project, I get an empty String as a response.
Why ?
Code: (BASE_URL = url before (including) the '?' , inputURL is the rest of the URL)
private static String accessURL(String inputURL) throws IOException{
String inputLine = "";
try {
URL oracle = new URL(BASE_URL + inputURL);
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
inputLine = in.readLine();
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} finally{
return inputLine;
}
}
And calling the function:
accessURL("type=1");
But when I paste the same code in my Android project, I get an empty String as a response.
Why ?
Code: (BASE_URL = url before (including) the '?' , inputURL is the rest of the URL)
private static String accessURL(String inputURL) throws IOException{
String inputLine = "";
try {
URL oracle = new URL(BASE_URL + inputURL);
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
inputLine = in.readLine();
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} finally{
return inputLine;
}
}
And calling the function:
accessURL("type=1");