http 请求被变成https请求

http 请求被变成https请求

现象描述

局部截图

仔细观察上图可以发现,网页中 img 标签 src 指向资源地址为 http 资源地址,但是在 network 面板查看发出的网络资源请求却变成了 https 请求,导致资源找不到报错404。(注:图片资源实际真实地址确实为 http 资源)

原因,因为添加如下CSP内容,将自动将http的不安全请求升级为https

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

但是如果去掉上述meta内容,页面可能会报错 “Mixed Content”,因为浏览器不允许安全的 https 页面混合请求不安全的 http 请求

发现在部分safari 浏览器或者 ios 手机内嵌h5页面,禁止请求混合内容

参考链接

https://blog.csdn.net/ganquanzhong/article/details/80392346?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.pc_relevant_is_cache&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.pc_relevant_is_cache

https://blog.csdn.net/weixin_30421809/article/details/101894853?utm_medium=distribute.pc_relevant.none-task-blog-title-3&spm=1001.2101.3001.4242 

https://www.dazhuanlan.com/2020/02/12/5e43a145c87f6/

http://www.ruanyifeng.com/blog/2016/09/csp.html

@萍2樱释ღ( ´・ᴗ・` )

打不死的小强
原文地址:https://www.cnblogs.com/mggahui/p/13932906.html