gpt4 book ai didi

Node.js 读取 ECONNRESET

转载 作者:太空宇宙 更新时间:2023-11-03 22:23:53 24 4
gpt4 key购买 nike

我在应用程序中使用 Express.js,但在向 adobe Analytics API 发出发布请求时收到错误。

我尝试添加 server.timeout 但它无法修复它......

这是错误消息:

Error: read ECONNRESET
at exports._errnoException (util.js:1028:11)
at TLSWrap.onread (net.js:572:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read'

这是失败的代码:

  pullClassifications(req) {
const dfd = q.defer();
const { username, password, payload } = req;
const data = wsse({username: username, password: password});
const wsseHeaders = {'X-WSSE': data.toString({ nonceBase64: true })};
const options = {
'method': 'post',
'headers': wsseHeaders,
'content-type': 'application/json',
'body': payload,
'json': true,
'url': 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetClassifications'
}

request(options, function(err, response, body) {
if(response.statusCode == 200) {
dfd.resolve(body);
} else {
dfd.reject({statusCode: response.statusCode, body: body});
}
})
return dfd.promise;
}

更新:
我尝试使用 Postman 发布相同的请求,它有效,在 630000 毫秒内返回响应。

此错误的原因是什么?有什么方法可以解决它吗?

最佳答案

您是否尝试过在请求中添加timeout选项?当你可以使用原生 Promise 时,为什么还要使用 Q Promise 库?旧的 NodeJs 版本?

https://github.com/request/request#timeouts

    const options = {
'timeout': 120 * 60 * 1000 //(120 seconds)
'method': 'post',
'headers': wsseHeaders,
'content-type': 'application/json',
'body': payload,
'json': true,
'url': 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetClassifications'
}

request(options, function(err, response, body) {...});

关于Node.js 读取 ECONNRESET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49610864/

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