2013-07-25 103 views
-1

我爲了將數據發送到我的web服務使用HttpPost GET HTTP響應代碼的Android

HttpPost httppost = new HttpPost(url); 
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8")); 

。我怎麼能得到http響應代碼(如200,404,500等)?

我不能夠使用getResponseCode()HttpURLConnection

+0

對不起, 非常感謝! –

+0

沒問題:)我會標記它,所以它可以關閉 – crocboy

+0

我已經打'標記這篇文章':) –

回答

1

更多你的代碼將是有益的,但在這裏我做的方式是這樣的:

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() 
+0

類不解決在Android –

1

通過

HttpResponse response = httpclient.execute(httppost); 
StatusLine statusLine = response.getStatusLine(); 
int code = statusline.getStatusCode();