Android and Web Request (GET)

Android 2.2, Galaxy Tab, API Version 8

It’s easy with apache http client, see below code

//getResponse from any URL
private String getResponse(uRL) throws ClientProtocolException, IOException
{
String strRepsonse = “”;
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(uRL));
StatusLine statusLine = response.getStatusLine();
//response.getEntity().getContent().re
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
BufferedReader rd = new BufferedReader(new
InputStreamReader(response.getEntity().getContent()));
String line = “”;
while ((line = rd.readLine()) != null) {
strRepsonse += line;
}
}
return strRepsonse;
}

I hope this is to the point 🙂

Thanks,
Riz

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.