解决PKIX path building failed的问题unable to find valid certification path to requested target
2014-09-23 14:52
761 查看
//问题
javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIXpathbuildingfailed:sun.security.provider.certpath.SunCertPathBuilderException:unabletofindvalidcertificationpathtorequestedtarget
<preclass="java"name="code">//在握手之前调用这两个方法 trustAllHttpsCertificates(); HttpsURLConnection.setDefaultHostnameVerifier(hv);
HostnameVerifierhv=newHostnameVerifier(){
publicbooleanverify(StringurlHostName,SSLSessionsession){
System.out.println("Warning:URLHost:"+urlHostName+"vs."
+session.getPeerHost());
returntrue;
}
publicbooleanverify(Strings,Strings1){
//TODOAuto-generatedmethodstub
returntrue;
}
};
privatestaticvoidtrustAllHttpsCertificates()throwsException{
javax.net.ssl.TrustManager[]trustAllCerts=newjavax.net.ssl.TrustManager[1];
javax.net.ssl.TrustManagertm=newmiTM();
trustAllCerts[0]=tm;
javax.net.ssl.SSLContextsc=javax.net.ssl.SSLContext
.getInstance("SSL");
sc.init(null,trustAllCerts,null);
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc
.getSocketFactory());
}
staticclassmiTMimplementsjavax.net.ssl.TrustManager,
javax.net.ssl.X509TrustManager{
publicjava.security.cert.X509Certificate[]getAcceptedIssuers(){
returnnull;
}
publicbooleanisServerTrusted(
java.security.cert.X509Certificate[]certs){
returntrue;
}
publicbooleanisClientTrusted(
java.security.cert.X509Certificate[]certs){
returntrue;
}
publicvoidcheckServerTrusted(
java.security.cert.X509Certificate[]certs,StringauthType)
throwsjava.security.cert.CertificateException{
return;
}
publicvoidcheckClientTrusted(
java.security.cert.X509Certificate[]certs,StringauthType)
throwsjava.security.cert.CertificateException{
return;
}
}
protectedfinalStringretrieveResponseFromServer(finalURLvalidationUrl,
finalStringticket){
HttpURLConnectionconnection=null;
try{
connection=(HttpURLConnection)validationUrl.openConnection();
finalBufferedReaderin=newBufferedReader(newInputStreamReader(
connection.getInputStream()));
Stringline;
finalStringBufferstringBuffer=newStringBuffer(255);
synchronized(stringBuffer){
while((line=in.readLine())!=null){
stringBuffer.append(line);
stringBuffer.append("\n");
}
returnstringBuffer.toString();
}
}catch(finalIOExceptione){
returnnull;
}catch(finalExceptione1){
returnnull;
}finally{
if(connection!=null){
connection.disconnect();
}
}
}
相关文章推荐
- 解决方案:PKIX path building failed:unable to find valid certification path to requested target
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX问题:unable to find valid certification path to requested target
- Pop3_解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX问题:unable to find valid certification path to requested target【X509TrustManager】
- 解决PKIX问题:unable to find valid certification path to requested target
- PKIX path building failed: unable to find valid certification path to requested target
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX问题:unable to find valid certification path to requested target
- 解决PKIX问题:unable to find valid certification path to requested target
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX:unable to find valid certification path to requested target 的问题
- 解决PKIX:unable to find valid certification path to requested target 的问题