android webview 加载https,访问不安全地址,设置为忽略证书

        Webview 可以通过loadUrl(String url) 等方法加载网页。http 可以直接加载,但 https 是经过ssl 加密的,如果这个网站的安全证书在Android无法得到认证,WebView加载的网页就会变成一个空白页,同时也不会弹出任何提示。但是我们可以通过设置下面的方法来忽略证书,从而去访问不安全的地址(比如https://inv-veri.chinatax.gov.cn/),下面是实现:

        mWebview.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
//                super.onReceivedSslError(view, handler, error);
                //handler.cancel();// super中默认的处理方式,WebView变成空白页
                if (handler != null) {
                    handler.proceed();//忽略证书的错误继续加载页面内容,不会变成空白页面
                }
            }

猜你喜欢

转载自blog.csdn.net/Wang_WY/article/details/86253980