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

我想從我的GH-頁(GH-頁Access-Control-Allow-Origin*HTTPS是通過瀏覽器取消我的要求被視爲HTTP requeset

獲取的json數據通過我所得到的是這樣的:

what code I use and what I get

,我檢查了Chrome的devtool網絡面板:

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請求將被reddirect到https

回答

1

https://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world的請求生成301(「感動永久」)至http://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world/,這是造成您的問題。

this blog post注意到如果您的網站在2016年6月15日之前已經存在,則需要在該網站的設置中手動啓用HTTPS支持。

+0

但我的網站是在9天前創建的,HTTPS強制執行 – Vanis