-1
我有一個奇怪的問題,我不知道如何調試它。如果長度超過1308字節,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
這個任何想法?
謝謝,
應該是服務器限制。重複http://stackoverflow.com/questions/2880722/is-http-post-limitless/2880766#2880766和其他...只是進行搜索。 – DiogoSantana 2013-03-28 03:10:51
我想不是這樣,因爲我在Windows機器上使用Fiddler2進行嘗試,並且對於大於1308bytes的請求,它工作正常。這是更多的客戶端配置我猜,但我不知道在哪裏檢查它。 – 2013-03-28 03:13:18
你有權訪問服務器嗎?您可能會溢出到另一個以太網幀中,並且服務器處理不好。 – BevynQ 2013-03-28 03:14:35