400 Bad Request. Sending HTTP POST call in Java that was tested in JMeter

578 views Asked by At

I'm trying to send a POST Request to a Webserver. The Call is tested in JMeter.

Test in JMeter (HTTP Request Details)

Now I've got the following code:

 //HEADER SECTION
    post.setHeader("Connection","keep-alive");
    post.setHeader("Host", "http://sv2XXX.XXX.XXX.XXX.com:8080");
    post.setHeader("Content-Type", "text/plain");
    
    
    //BODY SECTION
    ArrayList<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("","<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:api=\"http://api.XXX.XXX.XXX.com/\">" + 
            "<soap:Header>" + 
            "<api:userid>USER1</api:userid>" + 
            "</soap:Header>" + 
            "<soap:Body>" + 
            "<api:executeAbout>" + 
            "<About/>" + 
            "</api:executeAbout>" + 
            "</soap:Body>" + 
            "</soap:Envelope>"));

    post.setEntity(new UrlEncodedFormEntity(urlParameters));

Some how this results in a "400 Bad Request" Error. In my opinion this is caused by the empty name in the parameters declaration. But I don't know how to call it. Any ideas?

1

There are 1 answers

0
tifi90 On BEST ANSWER

I've found the error code in the german wikipedia article of HTTP Header Fields https://de.wikipedia.org/wiki/Liste_der_HTTP-Headerfelder. By the way the error code is not mentioned in the english article https://en.wikipedia.org/wiki/List_of_HTTP_header_fields.

It says when the host is missing in the header the server must answer with error code 400 Bad Request.

I've checked my header and found leading http://

Removing "http://" solved the problem.