解决android 6.0 webview加载https出现空白页问题

解决android 6.0 webview加载https出现空白页问题

由于公司项目换成的https接口,其他数据都能加载正常,而webview加载https页面出现空白页,查看logcat:
This request has been blocked; the content must be served over HTTPS

I/chromium: [INFO:CONSOLE(1)] "Mixed Content: The page at 'https://www.taranada.com/mobile/index.php?act=goods&op=goods_body&goods_id=100839' was loaded over HTTPS, but requested an insecure image 'http://www.taranada.com/data/upload/shop/store/goods/1/1_05294182983507327_1280.jpg'. This request has been blocked; the content must be served over HTTPS.", source: https://www.taranada.com/mobile/index.php?act=goods&op=goods_body&goods_id=100839 

解决办法:

 webView.setWebViewClient(new WebViewClient(){
    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){
       //注意:super句话一定要删除,或者注释掉,否则又走handler.cancel()默认的不支持https的了。
       //super.onReceivedSslError(view, handler, error);
       //handler.cancel(); // Android默认的处理方式
       //handler.handleMessage(Message msg); // 进行其他处理

        handler.proceed(); // 接受所有网站的证书
            }
        });

但是在6.0的手机上依然是显示空白页,
解决办法:添加如下代码

/**
 *  Webview在安卓5.0之前默认允许其加载混合网络协议内容
 *  在安卓5.0之后,默认不允许加载http与https混合内容,需要设置webview允许其加载混合网络协议内容
 */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {   
                   webview.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

}

参考:http://blog.csdn.net/u013270444/article/details/51889473
参考:http://blog.csdn.net/huangwenkui1990/article/details/51720732

你可能感兴趣的:(android)