Android の Web サービスにリクエストを送信しようとすると、ステータス 400 が返されます。どうすればこれを修正できますか?
これが私のリクエストコードです:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2:1455/Android/Android.svc/GetCompanyBusinessAreas2");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("company", companhiaIdS));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//httppost.g
//httppost.setEntity(new StringEntity(companhiaIdS));
Log.i("Enviando:", nameValuePairs.toString());
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Log.i("Resposta:", response.getEntity().toString());
Log.i("status","" + response.getStatusLine().getStatusCode());
HttpEntity responseEntity = response.getEntity();
char[] buffer = new char[(int) responseEntity.getContentLength()];
Log.i("buffer:","" + responseEntity.getContentLength());
try {
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
reader.close();
} catch (IOException e) {
e.printStackTrace();
Log.i("EXCEPTION", e.getMessage());
}
//FIM DA LIGACAO WCF
String reply2 = new String(buffer);
Log.i("teste", reply2);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
変数 companhiaIdS は文字列です。