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

whlk picture whlk · Apr 7, 2010 · Viewed 78.5k times · Source

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?

Answer

Robby Pond picture Robby Pond · Apr 7, 2010

This will return the int value:

response.getStatusLine().getStatusCode()