Search code examples
androidhttpclienthttprequesthttp-status-codes

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?


Solution

  • This will return the int value:

    response.getStatusLine().getStatusCode()