Mixed Content: xxx This request has been blocked; the content must be served over HTTPS.

本文介绍在HTTPS网页中引入HTTP资源导致的MixedContent问题及其解决方案。当HTTPS页面动态引入HTTP资源时,如JS文件或通过AJAX请求HTTP资源,浏览器会直接阻止这些不安全的请求。文章提供了一种解决方案,即在页面头部加入特定的元标签,自动将HTTP请求升级为HTTPS,以确保网页的安全性和完整性。

问题:如何在HTTPS 网页中引入HTTP资源: Mixed Content?

原因:HTTPS页面里动态的引入HTTP资源,比如引入一个js文件,会被直接block掉的.在HTTPS页面里通过AJAX的方式请求HTTP资源,也会被直接block掉的。

解决方案<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
在相应的页面的里加上这句代码,意思是自动将http的不安全请求升级为https

Mixed Content: The page at 'https://www.4399.com/flash/78072qh.htm' was loaded over HTTPS, but requested an insecure script 'http://newsimg.5054399.com/js/checkMobile.js'. This request has been blocked; the content must be served over HTTPS. 78072qh.htm:9 Uncaught ReferenceError: check_mobile is not defined at 78072qh.htm:9:9 (匿名) @ 78072qh.htm:9 78072qh.htm:16 document.domain mutation is ignored because the surrounding agent cluster is origin-keyed. (匿名) @ 78072qh.htm:16 78072qh.htm:161 Mixed Content: The page at 'https://www.4399.com/flash/78072qh.htm' was loaded over a secure connection, but contains a form that targets an insecure endpoint 'http://news.4399.com/zmxy3/search.php'. This endpoint should be made available over a secure connection. 78072qh.htm:63 Mixed Content: The page at 'https://www.4399.com/flash/78072qh.htm' was loaded over HTTPS, but requested an insecure frame 'http://sda.4399.com/4399swf/upload_swf/ftp7/hanbao/20120107/6/x3v0529.htm'. This request has been blocked; the content must be served over HTTPS. 78072qh.htm:1 Mixed Content: The page at 'https://www.4399.com/flash/78072qh.htm' was loaded over HTTPS, but requested an insecure script 'http://4399stat.5054399.com/js/click.js'. This request has been blocked; the content must be served over HTTPS. 78072qh.htm:1 Mixed Content: The page at 'https://www.4399.com/flash/78072qh.htm' was loaded over HTTPS, but requested an insecure script 'http://www.4399.com/js/4399stat.js'. This request has been blocked; the content must be served over HTTPS. 78072qh.htm:1 Mixed Content: The page at 'https://www.4399.com/flash/78072qh.htm' was loaded over HTTPS, but requested an insecure script 'http://s25.cnzz.com/stat.php?id=4073713&web_id=4073713&show=pic'. This request has been blocked; the content must be served over HTTPS.
最新发布
04-02
在Flutter中使用WebView时,如果遇到错误"This request has been blocked; the content must be served over HTTPS",这是因为现代浏览器和WebView都默认启用了安全策略,要求所有的请求必须通过HTTPS协议进行,而不是不安全的HTTP协议。 要解决这个问题,可以尝试以下几种方法: 1. **使用HTTPS**:确保你请求的资源是通过HTTPS协议提供的。将所有的资源链接从HTTP改为HTTPS。 2. **允许不安全的请求**:如果你无法使用HTTPS,可以在WebView的配置中设置允许不安全的请求。不过,这种方法不推荐在生产环境中使用,因为它会降低应用的安全性。 ```dart WebView( initialUrl: 'http://example.com', javascriptMode: JavascriptMode.unrestricted, onWebViewCreated: (WebViewController webViewController) { // 允许不安全的请求 webViewController.loadUrl('javascript:(function() {document.cookie = "cross-site-cookie=whatever; SameSite=None; Secure";})();'); }, ) ``` 3. **使用混合内容**:如果你使用的是混合内容(即在HTTPS页面中加载HTTP资源),可以通过配置WebView来允许混合内容。 ```dart import 'dart:io'; WebView( initialUrl: 'https://example.com', javascriptMode: JavascriptMode.unrestricted, onWebViewCreated: (WebViewController webViewController) { if (Platform.isAndroid) { webViewController.loadUrl('javascript:(function() {document.cookie = "cross-site-cookie=whatever; SameSite=None; Secure";})();'); } }, gestureNavigationEnabled: true, ) ``` 4. **检查请求的URL**:确保你请求的URL是正确的,没有拼写错误或其他问题。 通过以上方法,你应该能够解决WebView中出现的"This request has been blocked; the content must be served over HTTPS"错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值