网页访问报错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

发布了179 篇原创文章 · 获赞 16 · 访问量 22万+

猜你喜欢

转载自blog.csdn.net/yan_dk/article/details/94410647