简体   繁体   中英

Http Request Status 400

I am trying to send a request to a web service on Android and it returns status 400 I know status 400 means bad request, but I cant see anything wrong. How can I fix this?

Here is my request code:

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();
}

The variable companhiaIdS is a String.

yes it does mean bad request. That probably means the backend is unable to process the request

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM