android WebView加载不出网页内容This request has been blocked; the content must be served over HTTPS.
2017-04-21 10:27
1071 查看
项目中遇到加载网页的时候都出现加载不出内容或者内容不全。但是QQ浏览器或者系统浏览器都没问题,也就是还是自己写的Webview处理有问题。总结了一下大概下面两个问题引起:实际问题可以参看Android Studio
打印的Log,会有Webview的追踪内容为chromium: xxxxxx.
情况一:
无法加载JS内容写的页面。
设置setDomStorageEnabled,可能是webview前端写的一些代码便签不支持。
情况二:
出现部分内容显示部分内容不显示,打印日志大概如下:
chromium: [INFO:CONSOLE(15)] "Mixed Content: The page at 'https://dihao.moxz.cn/' was loaded over HTTPS, but requested an insecure image 'http://sm.domobcdn.com/hm/2017/landing/img/dihao/p5.jpg'.
This request has been blocked; the content must be served over HTTPS.", source: https://sm.domobcdn.com/hm/2017/landing/js/swiper.3.4.2.min.js (15)
这个是加载的地址是https的,一些资源文件使用的是http方法的,从安卓4.4之后对webview安全机制有了加强,webview里面加载https
url的时候,如果里面需要加载http的资源或者重定向的时候,webview会block页面加载。需要设置MixedContentMode,解决此问题的代码如下:
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setAllowFileAccess(true);
settings.setAppCacheEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
打印的Log,会有Webview的追踪内容为chromium: xxxxxx.
情况一:
无法加载JS内容写的页面。
设置setDomStorageEnabled,可能是webview前端写的一些代码便签不支持。
WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true);
情况二:
出现部分内容显示部分内容不显示,打印日志大概如下:
chromium: [INFO:CONSOLE(15)] "Mixed Content: The page at 'https://dihao.moxz.cn/' was loaded over HTTPS, but requested an insecure image 'http://sm.domobcdn.com/hm/2017/landing/img/dihao/p5.jpg'.
This request has been blocked; the content must be served over HTTPS.", source: https://sm.domobcdn.com/hm/2017/landing/js/swiper.3.4.2.min.js (15)
这个是加载的地址是https的,一些资源文件使用的是http方法的,从安卓4.4之后对webview安全机制有了加强,webview里面加载https
url的时候,如果里面需要加载http的资源或者重定向的时候,webview会block页面加载。需要设置MixedContentMode,解决此问题的代码如下:
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setAllowFileAccess(true);
settings.setAppCacheEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
相关文章推荐
- android WebView加载不出网页内容This request has been blocked; the content must be served over HTTPS.
- HTTPS调用百度地图API提示“BMap未定义, This request has been blocked; the content must be served over HTTPS.,was
- Mixed Content: xxx This request has been blocked; the content must be served over HTTPS.
- This request has been blocked; the content must be served over HTTPS.
- Mixed Content: The page was loaded over HTTPS,blocked the content must be served over HTTPS.
- Android - WebView 加载 Https 出现 SSL Error. Failed to validate the certificate chain
- android中的webview加载网页只想显示部分内容改怎么做
- android webView加载页面时显示出全部网页内容
- (转)HttpWebRequest以UTF-8编码写入内容时发生“Bytes to be written to the stream exceed the Content-Length bytes size specified.”错误
- Android webview加载https网页时图片无法加载显示问题
- Android webview加载https网页时http图片无法显示
- 详解android 用webview加载网页(https和http)
- Android之WebView——解决加载Https以及根据网页动态设置WebView高度等难题
- [原][Android]All WebView methods must be called on the same thread.
- HttpWebRequest以UTF-8编码写入内容时发生“Bytes to be written to the stream exceed the Content-Length bytes size specified.”错误
- Android webview 加载自签名的https网页显示空白
- Android webview 加载https网页显示空白
- [Android]WebView搭载WebContent时,网页加载速度太慢的对应策
- Python 出现错误 SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform.
- Android webview加载网页只想显示部分内容