Friday, April 27, 2012

Android: How get the status-code of an HttpClient request


I want to download a file and need to check the response status code (ie HTTP /1.1 200 OK ). This is a snipped of my code:




HttpGet httpRequest = new HttpGet(myUri);
HttpEntity httpEntity = null;
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httpRequest);
...



How do i get the status-code of the response?


Source: Tips4all

1 comment:

  1. This will return the int value:

    response.getStatusLine().getStatusCode()

    ReplyDelete