转载:网页访问报错This request has been blocked; the content must be served over HTTPS.

问题:网页有时访问https网站,由于网站中一些资源是http的,网页执行会报错“This request has been blocked;  the content must be served over HTTPS.”,chrome浏览器审查元素可以看到。

解决:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

可以在相应的页面的<head>里加上这句代码,意思是自动将http的不安全请求升级为https

可以在代码中判断服务器的协议类型是否为https,再加载上述代码,如下

{yun:}if strpos($config.sy_weburl,'https')!== false{/yun}
 <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> 
{yun:}/if{/yun}

参考:https://segmentfault.com/q/1010000005872734

原文链接:ps://blog.csdn.net/shenxiaomo1688/article/details/105435622/

原文地址:https://www.cnblogs.com/yaohuimo/p/14505044.html