Java: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

我们在平时练习的时候一般使用低版本的jdk来练习,以便了解不同版本jdk的区别,下面是我们练习中遇到的问题 >>>  

DefaultHttpClient mHttpClient =  new DefaultHttpClient(new BasicHttpParams());  
ClientConnectionManager ccm = mHttpClient.getConnectionManager();  
SchemeRegistry sr = ccm.getSchemeRegistry();  
SSLContext sslcontext = null;  
try {  
    sslcontext = SSLContext.getInstance("TLS");  
    sslcontext.init(null, new TrustManager[]{}, null);  
} catch (NoSuchAlgorithmException e) {  
    e.printStackTrace();  
}  
SSLSocketFactory ssf = new SSLSocketFactory(sslcontext);  
ssf.setHostnameVerifier(ALLOW_ALL_HOSTNAME_VERIFIER);  
sr.register(new Scheme("https", ssf, 443));   
PoolingClientConnectionManager pccm = new PoolingClientConnectionManager(sr);    
pccm.setDefaultMaxPerRoute(20); //每个主机的最大并行链接数     
pccm.setMaxTotal(100);          //客户端总并行链接最大数        
mHttpClient =  new DefaultHttpClient(pccm, mHttpClient.getParams());  
mHttpClient.execute(new HttpGet("https://www.xxx.com"));  

此代码在本地开发环境正常运行,但是在服务器上mHttpClient.execute会报错: 

Exception in thread "main" javax.NET.ssl.SSLPeerUnverifiedException: peer not authenticated

本地开发环境:jdk1.7,服务器运行环境 jdk1.6,本地jdk版本和服务器版本不一致的问题,参考链接:

java - Exception : javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated - Stack Overflow

Java: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated_第1张图片 升级服务器jdk到1.7后,问题解决

你可能感兴趣的:(java,.net,ssl)