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

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;
                }
            });

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

有问题之处烦请在留言中指出,非常感谢。

你可能感兴趣的:(android,error)