Android webview加载https网页时http图片无法显示

来源:互联网 发布:中国国家地理 知乎 编辑:程序博客网 时间:2024/05/16 23:48

今天碰到奇怪问题,我们加载网页从http改成https时,网页中的图片都无法加载。报错如下:


“Mixed Content: The page at ‘https://…’ was loaded over HTTPS,  
but requested an insecure image ‘http://image…..jpg‘.  
This content should also be served over HTTPS.”


原因:webview 从Lollipop(5.0)开始 webview默认不允许混合模式,https当中不能加载http资源,如果要加载,需单独设置开启。


解决方案: 

if (Build.VERSION.SDK_INT >= 21) {               webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); }