0

我正在尝试向 Web 服务器发送 POST 请求。调用在 JMeter 中进行了测试。

在 JMeter 中测试(HTTP 请求详细信息)

现在我有以下代码:

 //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 Bad Request”错误。在我看来,这是由参数声明中的空名称引起的。但我不知道怎么称呼它。有任何想法吗?

4

1 回答 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://”解决了这个问题。

于 2020-07-28T13:28:47.287 回答