-1

私は使用しています

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

私のWebサービスにデータを送信するため。http 応答コード (200、404、500 など) を取得するにはどうすればよいですか?

getResponseCode()から使えないHttpURLConnection

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 に答える