解决WebView加载出现白屏,显示X509 java.security.cert.CertPathValidatorException

场景

使用WebView加载某一网址时,不能正常显示网页,在Logcat出现以下错误提示。

I/X509Util: Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

解决方案

webView.setWebViewClient(new WebViewClient() {
     @Override
     public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
         //千万不能调用super的方法,super方法中默认取消了处理
		 //super.onReceivedSslError(view, handler, error);
         handler.proceed();
     }
 });
原创文章 65 获赞 26 访问量 10万+

猜你喜欢

转载自blog.csdn.net/adojayfan/article/details/88880931