【发布时间】:2021-06-16 18:54:45
【问题描述】:
此 URL 向 wget 和 curl 返回代码 301,但 node-fetch 报告的是 200:
# wget https://www.h24info.ma/feed
--2021-03-19 11:30:23-- https://www.h24info.ma/feed
Resolving www.h24info.ma (www.h24info.ma)... 104.21.39.120, 172.67.145.67, 2606:4700:3030::6815:2778, ...
Connecting to www.h24info.ma (www.h24info.ma)|104.21.39.120|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
# curl -I https://www.h24info.ma/feed
HTTP/2 301
但是 fetch 返回 200(并且永远挂起):
fetch('https://www.h24info.ma/feed', {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36',
'accept': 'text/html,application/xhtml+xml'
}).then(function (res) {
console.error('node-fetch status: %s', res.status);
});
node-fetch status: 200
我错过了什么吗? Fetch 应该返回 301,以便可以中止请求并处理错误。
| software | version |
|---|---|
| node-fetch | 2.6.1 |
| node | v14.15.3 |
| npm | 7.6.0 |
| Operating System | Linux 4.9.0-15-amd64 #1 SMP Debian 4.9.258-1 (2021-03-08) x86_64 GNU/Linux |
【问题讨论】:
标签: node.js http-error node-fetch