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

  • Post author:
  • Post category:其他


问题:网页有时访问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



版权声明:本文为yan_dk原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。