您的位置:首页 > 移动开发 > Android开发

android 屏蔽证书验证 CertPathValidatorException: Trust anchor for certification path not found

2017-08-04 15:54 615 查看
android 使用https时 证书如果是用来测试的会爆出下面问题:

javax.net.ssl.SSLHandshakeException:
java.security.cert.CertPathValidatorException:
Trust anchor for certification path not found


解决办法是将证书验证屏蔽掉:

HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");        urlConnection.setSSLSocketFactory(context.getSocketFactory());
urlConnection.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});


注意:在上线的时候如需验证需要将代码注释掉!!!!

有问题之处烦请在留言中指出,非常感谢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐