javascript - HTTPS请求被浏览器取消,并 被视作HTTP请求
伊谢尔伦
伊谢尔伦 2017-04-11 12:03:28
[JavaScript讨论组]
    fetch('https://vanishingdante.github.io/gh-pages-blog-api/2017/02/11/bye-world')
      .then(resp => resp.json())
      .then(json => console.log(json))

我用 fetch api 尝试从我的 gh-pages 获取 json 数据 (gh-pages Access-Control-Allow-Origi 的 为 *)

但是我得到的是这个

然后我检查了一下 Chrome devtool 的 Network

我的 HTTPS 请求被浏览器取消,并且该次请求被视作一次 HTTP 请求

为什么会这样,怎么处理这种情况

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(2)
高洛峰

你fetch的这个地址虽然是https的,但是里面是301跳转,又跳回http了。

[root@localhost ~]# 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 03:31:30 GMT
Cache-Control: max-age=600
X-GitHub-Request-Id: DCFE:28E4:64D5D4E:8722232:58AA60B9
Content-Length: 178
Accept-Ranges: bytes
Date: Mon, 20 Feb 2017 03:21:34 GMT
Via: 1.1 varnish
Age: 4
Connection: keep-alive
X-Served-By: cache-itm7424-ITM
X-Cache: HIT
X-Cache-Hits: 1
X-Timer: S1487560894.032116,VS0,VE0
Vary: Accept-Encoding
X-Fastly-Request-ID: e55e5f1de288a19b7772c1ac3902ce61bd121201

<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:

[root@localhost ~]# 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: A1F0:61E6:4D0C0CE:60DEE17:58AA6105
Content-Length: 178
Accept-Ranges: bytes
Date: Mon, 20 Feb 2017 03:22:45 GMT
Via: 1.1 varnish
Age: 0
Connection: keep-alive
X-Served-By: cache-itm7420-ITM
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1487560965.336320,VS0,VE191
Vary: Accept-Encoding
X-Fastly-Request-ID: f1d26de898e81b14cf0dacbe28ad6dc716fca747

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

你的gh-pages有问题。

怪我咯

你网站是https的,但是你使用的http的资源。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号