javascript - 节点获取连接 ETIMEDOUT 错误
问题描述
我试图获得 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' }
解决方案
看起来是因为代理限制。
推荐阅读
- java - 在 Java BlockingQueue 中处理不同的事件类型
- webdriver-io - WebdriverIO 7:chromedriver 以小分辨率打开
- docker - 使用 gitlab cicd 使用 nodemon 部署 express
- spring-boot - 在 Spring Boot 中使用投影和自定义 SQL
- python - 在 groupby - pandas 上指定可能的值
- linux - 按照从包安装到字母,但得到错误:致命 - 用户“ckan_default”的密码身份验证失败
- html - 如何在 Django 和 postgresql 中使用我的数据库中的字段填写 html 表单?
- mysql - 最近 3 个月的销售额滚动 SQl、MYSQL
- javascript - 我想用“ ”显示分页
- python - 熊猫获得连续的行