英文:
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.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
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.
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
得分: 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论