发新话题
打印

https站点调取http外部资源问题

https站点调取http外部资源问题

最近做一个H5项目,嵌入到合作放的app里,但要求用https的方式,之前项目都是按http做的,所以要改引入的话有些地方改不了,比如外部的图片,这样导致用http引入的图片不会显示,经客户端联调发现有如下报错:
04-17 19:52:50.051: Iromium(4453): [INFO:CONSOLE(0)] "Mixed Content: The page at 'https://q.51...g%3D' was loaded over HTTPS, but requested an insecure image '[img]file:///C:\Users\h5\AppData\Local\Temp\[5UQ[BL(6~BS2JV6W}N6[%S.png[/img]http://m.zhcw.com/upload/resources/image/2017/04/14/562272.png'. This request has been blocked; the content must be served over HTTPS.", source: https://q.51...g%3D
解决方案:

W3C 工作组考虑到了我们升级 HTTPS 的艰难,在 2015 年 4 月份就出了一个 Upgrade Insecure Requests 的草案([img]file:///C:\Users\h5\AppData\Local\Temp\[5UQ[BL(6~BS2JV6W}N6[%S.png[/img]http://www.w3.org/TR/mixed-content/),他的作用就是让浏览器自动升级请求。
在我们服务器的响应头中加入:
header("Content-Security-Policy: upgrade-insecure-requests");
我们的页面是 https 的,而这个页面中包含了大量的 http 资源(图片、iframe等),页面一旦发现存在上述响应头,会在加载 http 资源时自动替换成 https 请求。

遗留问题:
感觉访问速度受到影响,目前没时间排查。

[ 本帖最后由 xiexie 于 2017-5-9 19:58 编辑 ]

TOP

发新话题