Android: Having trouble getting html from webpage
Posted
by
Kyle
on Stack Overflow
See other posts from Stack Overflow
or by Kyle
Published on 2011-01-17T23:34:02Z
Indexed on
2011/01/17
23:53 UTC
Read the original article
Hit count: 205
Hi,
I'm writing an android application that is supposed to get the html from a php page and use the parsed data from thepage. I've searched for this issue on here, and ended up using some code from an example another poster put up. Here is my code so far:
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
try {
Log.d("first","first");
HttpResponse response = client.execute(request);
String html = "";
Log.d("second","second");
InputStream in = response.getEntity().getContent();
Log.d("third","third");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
Log.d("fourth","fourth");
StringBuilder str = new StringBuilder();
String line = null;
Log.d("fifth","fifth");
while((line = reader.readLine()) != null) {
Log.d("request line",line);
}
in.close();
} catch (ClientProtocolException e) {
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("error", "error");
}
Log.d("end","end");
}
Like I said before, the url is a php page. Whenever I run this code, it prints out the first first message, but then prints out the error error message and then finally the end end message. I've tried modifying the headers, but I've had no luck with it. Any help would be greatly appreciated as I don't know what I'm doing wrong.
Thanks!
© Stack Overflow or respective owner