浏览器取消HTTPS,我的请求被视为HTTP requeset

时间:2017-02-19 18:44:44

标签: javascript http web cors github-pages

fetch('https://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world')
  .then(resp => resp.json())
  .then(json => console.log(json))

我试图从我的gh页面获取我的json数据(gh-pages'Access-Control-Allow-Origin*

我得到的是:

what code I use and what I get

我检查了Chrome的开发工具中的网络面板:

network panel in Chrome's devtool

https请求被浏览器取消,我的提取被视为http请求。

为什么以及如何解决这个问题

curl https://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world -i

将获得:

HTTP/1.1 301 Moved Permanently
Server: GitHub.com
Content-Type: text/html
Location: http://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world/
Access-Control-Allow-Origin: *
Expires: Mon, 20 Feb 2017 07:08:43 GMT
Cache-Control: max-age=600
X-GitHub-Request-Id: F932:2F9ED:6B263C9:9012708:58AA93A3
Content-Length: 178
Accept-Ranges: bytes
Date: Mon, 20 Feb 2017 06:58:43 GMT
Via: 1.1 varnish
Age: 0
Connection: keep-alive
X-Served-By: cache-nrt6121-NRT
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1487573923.394396,VS0,VE179
Vary: Accept-Encoding
X-Fastly-Request-ID: 7acb3e168a104bffe672ee2c77215cd750197a3f

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

对https的请求将重定向到http

curl http://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world -i

将获得:

HTTP/1.1 301 Moved Permanently
Server: GitHub.com
Content-Type: text/html
Location: https://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world
X-GitHub-Request-Id: C9E0:786B:3CE9A28:5028A16:58AA941A
Content-Length: 178
Accept-Ranges: bytes
Date: Mon, 20 Feb 2017 07:00:43 GMT
Via: 1.1 varnish
Age: 0
Connection: keep-alive
X-Served-By: cache-nrt6122-NRT
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1487574043.118608,VS0,VE179
Vary: Accept-Encoding
X-Fastly-Request-ID: d4377ad8a08c54c1328558908b91941739f27279

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

和http请求将重定向到https

1 个答案:

答案 0 :(得分:1)

https://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world的请求会生成301(&#34;永久移动&#34; )到http://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world/,这会导致您的问题。

this blog post中,它注意到如果您的网站在2016年6月15日之前已经存在,则需要在网站设置中手动启用HTTPS支持。