Android HttpResponse response Code [duplicate]

2019-02-17 21:36发布

问题:

This question already has an answer here:

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

I am trying to get the response code for the HttpReponse. There is no method for get the response code directly.

回答1:

HttpResponse.getStatusLine().getStatusCode() is what you are looking for.



回答2:

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

Hopefully, it will help you.

Regards,

Android Geek.



回答3:

This is how you get Response code if you are using HttpUrlConnection :

int status = ((HttpURLConnection) connection).getResponseCode();
Log.i("", "Status : " + status);

And here is if you are using HttpClient :

HttpResponse response = httpclient.execute(httppost);
Log.w("Response ","Status line : "+ response.getStatusLine().toString());


标签: android http