0
我想向Android上的Web服务发送请求,并返回状态400我知道状态400意味着不好的请求,但我不能看到任何错误。我怎样才能解决这个问题?HTTP请求状态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是一个字符串。
它是否意味着该服务正在等待我发送的内容的不同类型参数? – 2013-05-10 14:48:38
可能是的,它的确如此 – Blackbelt 2013-05-10 14:49:35
通常,当我尝试调试Web服务器时,我通过“telnet * server * 80”手动执行请求并手动输入http请求。这很慢,但它将客户端应用程序排除在外,您可以确定问题是否出现在客户端的服务器上。 – 2013-05-10 15:51:44