85
我想下載一個文件並需要檢查響應狀態碼(即HTTP /1.1 200 OK
)。 這是一個剪斷我的代碼:Android:如何獲取HttpClient請求的狀態碼
HttpGet httpRequest = new HttpGet(myUri);
HttpEntity httpEntity = null;
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httpRequest);
...
我要如何響應的狀態碼?
然後你可以用HTTP狀態代碼比較http://developer.android.com/reference/org/apache/http/HttpStatus.html – thanhbinh84 2011-12-27 08:30:49
由於HttpStatus是一個不贊成的類,有沒有更好的類來使用? – gaara87 2015-05-06 18:10:36
@AkashRamani - 是的,只需使用HttpUrlConnection方法:.getResponseCode() – 2015-07-31 21:16:08