400 错误请求。在 JMeter 中测试的 Java 中发送 HTTP POST 调用
400 Bad Request. Sending HTTP POST call in Java that was tested in JMeter
我正在尝试向 Web 服务器发送 POST 请求。该调用已在 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<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));
了解这是如何导致“400 错误请求”错误的。在我看来,这是由参数声明中的空名称引起的。但是我不知道怎么称呼它。有什么想法吗?
我在 HTTP Header 字段 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.
的德语维基百科文章中找到了错误代码
它表示当 header 中缺少主机时,服务器必须使用错误代码 400 错误请求进行应答。
我检查了我的 header 并找到了领先的 http://
删除“http://”解决了问题。
我正在尝试向 Web 服务器发送 POST 请求。该调用已在 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<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));
了解这是如何导致“400 错误请求”错误的。在我看来,这是由参数声明中的空名称引起的。但是我不知道怎么称呼它。有什么想法吗?
我在 HTTP Header 字段 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.
的德语维基百科文章中找到了错误代码它表示当 header 中缺少主机时,服务器必须使用错误代码 400 错误请求进行应答。
我检查了我的 header 并找到了领先的 http://
删除“http://”解决了问题。