日期:2014-05-18  浏览次数:20794 次

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);
       &nb