gpt4 book ai didi

javascript - Node 获取连接 ETIMEDOUT 错误

转载 作者:行者123 更新时间:2023-11-30 06:24:02 28 4
gpt4 key购买 nike

我正在尝试获取 200 状态代码作为响应,但结果是 ETIMEDOUT。我不明白,我怎么可能通过 postman 获取成功的响应,但同样通过 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' }

最佳答案

看起来是因为代理限制。

关于javascript - Node 获取连接 ETIMEDOUT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51523378/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com