com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: java.security.cert.CertP

错误详情:
 com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: 
java.security.cert.CertPathValidatorException: 
Trust anchor for certification path not found. 
在继承的Application类里面onCreat()方法中调用该方法忽略https的证书校验(尽量让后台传正确的证书)
@SuppressLint("TrulyRandom")
public static void handleSSLHandshake() {
    try {
        TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return new X509Certificate[0];
            }

            @Override
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        }};

        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });
    } catch (Exception ignored) {
    }
}

你可能感兴趣的:(Android基础)