0

我正在尝试向 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 是一个字符串。

4

1 回答 1

0

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

于 2013-05-10T14:46:47.253 回答