Retrieve the contents of a stream via a HTTP GET.
public static InputStream getInputStreamFromUrl(String url) {
InputStream content = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
content = response.getEntity().getContent();
} catch (Exception e) {
Log.("[GET REQUEST]", "Network exception", e);
}
return content;
}
4 Comments
Nice, but it should be:
Log.e("[GET REQUEST]", "Network exception");
instead of
Log.("[GET REQUEST]", "Network exception", e);
;)
Tom
@Tom: Why? If you pass the Throwable (Exception) it'll log it.
should this be in a thread or the HttpClient have it's own thread?
Sidenote: You can read the
InputStreaminto a String with this sippet: http://www.androidsnippets.com/get-the-content-from-a-httpresponse-or-any-inputstream-as-a-string