如果长度超过1308字节,则Http POST请求不会得到响应

时间:2013-03-28 03:00:29

标签: java web-services soap http-post

我有一个奇怪的问题,我不知道如何调试它。

我需要向WebService服务器发出POST SOAP请求。

我的Java代码是:

    String urlParameters = "<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
..................
</soap:Body>
</soap:Envelope>";
        URL url;
        HttpURLConnection connection = null;  
        try {
        //Create connection
        url = new URL(targetURL);
        connection = (HttpURLConnection)url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
        connection.setRequestProperty("SOAPAction", "http://xxxxx/Foo" );

        connection.setUseCaches (false);
        connection.setDoInput(true);
        connection.setDoOutput(true);

        //Send request
        DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
        wr.writeBytes (urlParameters);
        wr.flush ();
        wr.close ();

        //Get Response  
          InputStream is = connection.getInputStream();
          BufferedReader rd = new BufferedReader(new InputStreamReader(is));
          String line;
          StringBuilder response = new StringBuilder(); 
          while((line = rd.readLine()) != null) {
            response.append(line);
            response.append('\r');
          }
          rd.close();

现在,如果urlParameters小于或等于1308字节,那么它工作正常,我可以得到响应。但是,如果长度超过1308字节(即如果我再添加一个字符到字符串),那么它就不会工作(它似乎甚至没有离开客户机,它永远不会到达服务器)

我尝试使用soapUI,它也给了我同样的问题。 我在Ubuntu 12.04上运行

是的,我确实有与CURL相同的问题。如果请求长度有效,则输出如下:

* About to connect() to epermit port 8085 (#0)
*   Trying 192.168.14.100... connected
> POST /xxx/xxx.asmx HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: xxx:8085
> Accept: */*
> Content-Type:text/xml; charset=utf-8
> SOAPAction:"xxxxx"
> Content-Length: 1304
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Cache-Control: private, max-age=0
< Content-Type: text/xml; charset=utf-8
< Server: Microsoft-IIS/7.5
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< Date: Thu, 28 Mar 2013 03:52:55 GMT
< Content-Length: 324
< 
* Connection #0 to host epermit left intact
* Closing connection #0
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><xxxx xmlns="xxxxxxx" /></soap:Body></soap:Envelope>

当我将请求大于1308字节时:

* About to connect() to xxxxxxxxxxx port 8085 (#0)
*   Trying 192.168.14.100... connected
> POST /xxxxxxx/xxxxxxx.asmx HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: xxxxxxxx:8085
> Accept: */*
> Content-Type:text/xml; charset=utf-8
> SOAPAction:"xxxxxxxxxxxxxxxxx"
> Content-Length: 1309
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue

对此有何想法?

感谢,

1 个答案:

答案 0 :(得分:0)

数据通过一系列数据包沿网络发送。这些分组的大小<=网络的MTU,这通常是低于1500个八位字节的一些数字。我怀疑服务器正在获取其中两个数据包而只读取第一个数据包。然后尝试解析不完整的数据失败。