Android:如何获取HttpClient请求的状态码
我想下载一个文件,需要检查响应状态码(即HTTP /1.1 200 OK
)。 这是我的代码片断:
HttpGet httpRequest = new HttpGet(myUri); HttpEntity httpEntity = null; HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(httpRequest); ...
我如何获得响应的状态码?
这将返回int
值:
response.getStatusLine().getStatusCode()
if (response.getStatusLine().getStatusCode()== HttpsURLConnection.HTTP_OK){ ... }