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

蹲街弑〆低调 提交于 2019-11-26 08:02:45

问题


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?


回答1:


This will return the int value:

response.getStatusLine().getStatusCode()



回答2:


if (response.getStatusLine().getStatusCode()== HttpsURLConnection.HTTP_OK){
...
}


来源:https://stackoverflow.com/questions/2592843/android-how-get-the-status-code-of-an-httpclient-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!