400 Bad Request. 在Java中发送HTTP POST调用,已在JMeter中测试过。

huangapple go评论79阅读模式
英文:

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

问题

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

现在我有以下代码:

//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 urlParameters = new ArrayList();
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:Headerapi:useridUSER1</api:userid></soap:Header>soap:Bodyapi:executeAbout</api:executeAbout></soap:Body></soap:Envelope>"));

post.setEntity(new UrlEncodedFormEntity(urlParameters));

Somehow 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?

英文:

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

400 Bad Request. 在Java中发送HTTP POST调用,已在JMeter中测试过。

Now I've got the following code:

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

    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

得分: 0

我在德国维基百科的HTTP Header Fields文章https://de.wikipedia.org/wiki/Liste_der_HTTP-Headerfelder中找到了错误代码。顺便说一下,这个错误代码在英文文章https://en.wikipedia.org/wiki/List_of_HTTP_header_fields中没有提到。

文章中说,当请求头中缺少主机信息时,服务器必须以错误代码400 Bad Request进行响应。

我检查了我的请求头并发现了以"http://"开头的部分。

移除"http://"解决了这个问题。

英文:

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.

huangapple
  • 本文由 发表于 2020年7月28日 18:32:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63132082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定