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

Advertisement