Weblogic: Exceeded stated content-length

            URL url = new URL("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl");
            URLConnection conn = url.openConnection();
            conn.setUseCaches(false);
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestProperty("Content-Length", Integer.toString(soap.length()));
            conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
            conn.setRequestProperty("SOAPAction", http://WebXml.com.cn/getWeatherbyCityName);

 

在tomcat下好使,但是在WebLogic下就挂了,报错

 

java.net.ProtocolException: Exceeding stated content length of 358


怎么会超长呢?

 

原因:

content-length这个是所传报文的byte类型的长度,而并非string字符串的长度,tomcat的编码格式iso-8859-1 ,而weblogic是GBK(或UTF-8)

这样就导致了超长。

 

解决办法:

conn.setRequestProperty("Content-Length", String.valueOf(soap.getBytes().length))就OK了!

  

转自:http://hite.iteye.com/blog/681903

你可能感兴趣的:(Weblogic: Exceeded stated content-length)