Android - WebView 加载 Https 出现 SSL Error. Failed to validate the certificate chain

1. 可以看

https://github.com/oauth-io/oauth-android/issues/2


2.错误信息

SSL Error. Failed to validate the certificate chain,error: java.security.cert.CertPathValidatorExcept

3.解决

 private class MyWebViewClient extends WebViewClient {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            return isLoading;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){
            handler.proceed(); //解决方案在此,不要调用super.xxxx
        }
    }

简洁版

webView.setWebViewClient(new WebViewClient() {
    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){
        handler.proceed();
    }
});

你可能感兴趣的:(android项目,产品研发)