我正在尝试获取200状态代码作为响应,但结果是ETIMEDOUT。 我不明白,我怎么可能通过邮递员来获得成功的响应,而通过 node-fetch 总是以ETIMEDOUT响应来获得成功。 这是代码示例:
const Resource = {
get: cb => {
fetch('https://example.com', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: {...some body...},
}).then(res => {
if (res.status !== 200) cb(`Status: ${res.status}, ${res.statusText}`)
return res.text()
}).then(data => {
cb(null, data)
}).catch((err) => {
console.log('ERROR: ', err)
})
}
}
这是回应:
ERROR: { FetchError: request to https://example.com failed, reason: connect ETIMEDOUT
at ClientRequest.<anonymous> (C:\Users\projects\DSSRQ\node_modules\node-fetch\lib\index.js:1393:11)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at TLSSocket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
message: 'request to https://example.com failed, reason: connect ETIMEDOUT',
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT' }
答案 0 :(得分:0)
这似乎是由于代理限制所致。