Android:如何获取 HttpClient 请求的状态代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2592843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:28:12 来源:igfitidea点击:
Android: How get the status-code of an HttpClient request
提问by whlk
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:
我想下载一个文件,需要检查响应状态代码(即HTTP /1.1 200 OK
)。这是我的代码片段:
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?
我如何获得响应的状态代码?
回答by Robby Pond
This will return the int
value:
这将返回int
值:
response.getStatusLine().getStatusCode()
回答by NickUnuchek
if (response.getStatusLine().getStatusCode()== HttpsURLConnection.HTTP_OK){
...
}