HttpPost获取HTTP响应代码Android

HttpPost获取HTTP响应代码Android,android,http,Android,Http,我正在使用 HttpPost httppost = new HttpPost(url); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8")); 以便将数据发送到我的Web服务。如何获得http响应代码,如200、404、500等 我无法通过从HttpURLConnection使用getResponseCode 您的更多代码在这里可能会有所帮助,但我的做法是: HttpClient client = new D

我正在使用

HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
以便将数据发送到我的Web服务。如何获得http响应代码,如200、404、500等

我无法通过从HttpURLConnection使用getResponseCode


您的更多代码在这里可能会有所帮助,但我的做法是:

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中无法解析
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()