我要下载文件,需要检查响应状态代码(即HTTP /1.1 200 OK
)。这是我的代码片段:
HttpGet httpRequest = new HttpGet(myUri);
HttpEntity httpEntity = null;
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httpRequest);
...
如何获取响应的状态码?
Answers:
这将返回int
值:
response.getStatusLine().getStatusCode()
if(getResponseCode()==200)
。我宁愿说if(getResponseCode()==HttpStatus.RESPONSE_OK)
还是类似的话。