Https下请求Http资源(blocked mixed-content)

  • A+
所属分类:网站建设
摘要

chrome浏览器下可以看出报错(blocked mixed-content)?怎么解决?

http与https下相互请求的问题。经过查询发现,http页面请求https不会出现问题,但是https页面请求http资源会弹出提示,甚至是挂掉,chrome浏览器下可以看出报错(blocked mixed-content)?怎么解决?

第一种方法:

<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">

比如这里我用了bootcss的cdn,但是正常情况下这样写是会报blocked mixed-content错误的。
解决方法:

<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">

这样的话浏览器就会根据你域名的请求来识别,比如https下他会自动请求https的资源,而http时,请求http的资源。
但是有可能他并不存在https的资源,但是我又想在Https下用这个cdn怎么办呢?

第二种方法:

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

这样他会在请求Http资源的时候先将他转成Https再请求。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: