私は使用しています
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
私のWebサービスにデータを送信するため。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()
に
HttpResponse response = httpclient.execute(httppost);
StatusLine statusLine = response.getStatusLine();
int code = statusline.getStatusCode();