You need a HttpClient
to perform a HttpGet
Request. Then you can read the content of that request.
This snippet gives you an InputStream
:
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.e("[GET REQUEST]", "Network exception", e);
}
return content;
}
And this method returns the String
:
// Fast Implementation
private StringBuilder inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
while ((line = rd.readLine()) != null) {
total.append(line);
}
// Return full string
return total;
}
Source: http://www.androidsnippets.com/executing-a-http-get-request-with-httpclient and http://www.androidsnippets.com/get-the-content-from-a-httpresponse-or-any-inputstream-as-a-string