首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

HttpsURLConnection 实现SOAP产生异常

2013-02-28 
HttpsURLConnection 实现SOAP产生错误本帖最后由 mythos55 于 2013-02-21 16:43:38 编辑SSLContext sc S

HttpsURLConnection 实现SOAP产生错误
本帖最后由 mythos55 于 2013-02-21 16:43:38 编辑

SSLContext sc = SSLContext.getInstance("SSL"); 
//指定信任https
sc.init(null, new TrustManager[]{new MyX509TrustManager()}, new java.security.SecureRandom());
URL console = new URL(Url+actionString);
HttpsURLConnection httpsConn = (HttpsURLConnection) console.openConnection(); 

//HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());  
httpsConn.setSSLSocketFactory(sc.getSocketFactory()); 

//http = (HttpsURLConnection) console.openConnection();  
            ((HttpsURLConnection) httpsConn).setHostnameVerifier(DO_NOT_VERIFY);
            //设置SOAPAction参数
          //  httpsConn.set
            httpsConn.setConnectTimeout(connectionTimeOut);
            httpsConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); 
            httpsConn.setRequestProperty("charset", "UTF-8");
            httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);
            httpsConn.setRequestProperty("Host", soapHost);
            httpsConn.setRequestProperty("ContentLength", Integer.toString(rqinfo.length));
            httpsConn.setReadTimeout(30000);
            httpsConn.setRequestMethod("POST");
            httpsConn.setDoOutput(true);
            httpsConn.setDoInput(true);



java.io.IOException: Server returned HTTP response code: 500 for URL: https://xxxx
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
怀疑是httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);这里的问题
[解决办法]
500说明服务器端已经收到发去的soap消息了,多半已经是业务逻辑层面的问题了,你怀疑的应该没错
[解决办法]

 httpsConn.setConnectTimeout(connectionTimeOut);
            httpsConn.setRequestProperty("Content-Type", "text/xml"); 
            httpsConn.setRequestProperty("charset", "UTF-8");
            httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);//确保你这个地方的字符串正确
            httpsConn.setRequestProperty("Host", soapHost);
            httpsConn.setRequestProperty("Content-Length", Integer.toString(rqinfo.length));


            httpsConn.setReadTimeout(30000);
            httpsConn..setUseCaches (false);//不使用缓存
            httpsConn.setRequestMethod("POST");
            httpsConn.setDoOutput(true);
            httpsConn.setDoInput(true);


改为这样试试


[解决办法]
 httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);总觉得你这个地方有问题,debug下看下。哪里开始报错的
[解决办法]


  InputStreamReader insr = new InputStreamReader(httpsConn
                    .getInputStream());//不要指定编码格式了,你不确定
            int respInt = insr.read();
            while (respInt != -1) {
                System.out.print((char) respInt);
                respInt = insr.read();
            }

[解决办法]
引用:
在后面报错的
Java code?12345   OutputStream out = httpConn.getOutputStream();            out.write(rqinfo);            StringBuffer receivedData = new StringBuffer();            InputStreamRea……

应该调试服务端

热点排行