-1

我正在使用

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

为了将数据发送到我的网络服务。如何获得 http 响应代码(如 200、404、500 等)?

我无法使用getResponseCode()fromHttpURLConnection

4

2 回答 2

3

您的更多代码在这里会有所帮助,但我这样做的方式是:

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()
于 2013-07-25T22:07:58.710 回答
1

经过

HttpResponse response = httpclient.execute(httppost);
StatusLine statusLine = response.getStatusLine();
int code = statusline.getStatusCode();
于 2013-07-25T22:07:33.280 回答