技术饭

在https中发ajax请求http被浏览器block

copylian    0 评论    12112 浏览    2018.12.26

1)强制升级http 静态资源地址为https地址

https页面中不能使用http请求,http页面中可以使用https请求。

关于在https 页面有一些http的请求,可以在<head></head>中设置

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

来自动升级http到https,就不需要修改源代码了。

 如果有些浏览器不支持,可以设置

php

header("Content-Security-Policy: upgrade-insecure-requests");

jsp:

如jsp页面<head></head>标签中可以这样设置

<%response.setHeader("Content-Security-Policy","upgrade-insecure-requests");%>

注意:只针对静态资源 如<script src="">  ,<img src="">,  <link href="" rel="stylesheet"> , <iframe src=""></iframe> ,  ajax请求 ,等

对于<a href="">  <script> window.location.href=""</script>不起作用

2)https 页面超链接,及iframe 地址为http的问题

https页面可以直接跳转到 http页面。

如果一个https页面中包含一个iframe,则此iframe的src不能为http地址

如果一个 https页面加载的一个iframe 页面中,包含一个http超链接,则此超链接必须加上 target="_blank",此时会在新的页面打开。如果target="_self"则不会跳转。

3)https页面中不能使用http的ajax地址

可以使用(1)中代码自动升级http到https

只袄早~~~
感谢你的支持,我会继续努力!
扫码打赏,感谢您的支持!

文明上网理性发言!

  • 还没有评论,沙发等你来抢