Http请求状态400

时间:2013-05-10 14:44:58

标签: android http

我正在尝试向Android上的Web服务发送请求并返回状态400我知道状态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是一个String。

1 个答案:

答案 0 :(得分:0)

是的,这确实意味着糟糕的要求。这可能意味着后端无法处理请求