最近遇到一个问题,在webview里面加载https url的时候,如果里面需要加载http的资源或者重定向的时候,webview会block页面加载。
错误信息如下:
chromium: [INFO:CONSOLE(0)] "Mixed Content: The page at 'https://iot.onehaier.com/v2/cms/advert.detail.h5?advertId=201612141722070002' was loaded over HTTPS, but requested an insecure image 'http://onehaiercms.oss-cn-qingdao.aliyuncs.com/2016/12/14/17-21-340871526087485.jpg'. This request has been blocked; the content must be served over HTTPS., source: https://iot.onehaier.com/v2/cms/advert.detail.h5?advertId=201612141722070002 (0)
修改内容如下:
//打开DOM储存API settings.setDomStorageEnabled(true); settings.setAllowFileAccess(true); settings.setAppCacheEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); }