I have a problem with the Android http url connection. I have this method:
private String getHtml(String urlString) throws Exception {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
URL url = new URL(urlString);
URLConnection uc = url.openConnection();
uc.setRequestProperty("Authorization", "Basic " + password);
InputStream content = uc.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = in.readLine()) != null) {
pw.println(line);
}
return sw.toString();
}
When I use it from a normal java application it works just fine. But when I run it from within an Android application it doesn't work.
I have observed that the url connection is an org.apache...HttpURLConnection when run in Android. And when it uses this it doesn't enter the while-loop.
In the normal java application it uses a sun.net...HttpURLConnection (which works).
Anyone have any suggestions to how I can get this to work on Android?