67,550
社区成员




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);
String responseInfo = null;
BufferedReader input = null;
byte rqinfo[] = requestInfo.getBytes();
//设置代理
//System.setProperty("proxyType", "4");
System.setProperty("proxyPort", proxyPort);
System.setProperty("proxyHost", proxyHost);
System.setProperty("proxySet", proxyFlag);
logger.info("GreenTreePubInfoaa begin");
try {
// KeyStore ks = KeyStore.getInstance("jks");
// ks.load(new FileInputStream("D:/greentree.cer"), "changeit".toCharArray());
// KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
// kmf.init(ks, "changeit".toCharArray());
SSLContext sc = SSLContext.getInstance("SSL");
//指定信任https
sc.init(null, new TrustManager[]{new MyX509TrustManager()}, new java.security.SecureRandom());
URL console = new URL(greenTreeUrl+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");
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.setUseCaches (false);//不使用缓存
httpsConn.setRequestMethod("POST");
httpsConn.setDoOutput(true);
httpsConn.setDoInput(true);
httpsConn.connect() ;
貌似也不行,还是一样的错误,我的还在system里面设置代理了。。也不知道哪儿出了问题
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);
改为这样试试
InputStreamReader insr = new InputStreamReader(httpsConn
.getInputStream());//不要指定编码格式了,你不确定
int respInt = insr.read();
while (respInt != -1) {
System.out.print((char) respInt);
respInt = insr.read();
}
OutputStream out = httpConn.getOutputStream();
out.write(rqinfo);
StringBuffer receivedData = new StringBuffer();
InputStreamReader inReader = new InputStreamReader(httpConn
.getInputStream(), "UTF-8");//这开始报错
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)