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

猜你喜欢

转载自blog.csdn.net/u013310119/article/details/81903188