我爲了將數據發送到我的web服務使用HttpPost GET HTTP響應代碼的Android
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
。我怎麼能得到http響應代碼(如200,404,500等)?
我不能夠使用getResponseCode()
從HttpURLConnection
我爲了將數據發送到我的web服務使用HttpPost GET HTTP響應代碼的Android
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
。我怎麼能得到http響應代碼(如200,404,500等)?
我不能夠使用getResponseCode()
從HttpURLConnection
更多你的代碼將是有益的,但在這裏我做的方式是這樣的:
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
HttpResponse response = client.execute(httppost);
int responseCode = response.getStatusLine().getStatusCode()
類不解決在Android –
通過
HttpResponse response = httpclient.execute(httppost);
StatusLine statusLine = response.getStatusLine();
int code = statusline.getStatusCode();
對不起, 非常感謝! –
沒問題:)我會標記它,所以它可以關閉 – crocboy
我已經打'標記這篇文章':) –