我在我的应用程序中使用Express.js,当我向analytics发出post请求时会出现错误。
我试着添加server.timeout,但它不能修复它.
这是错误消息:
错误:请阅读ECONNRESET 在exports._errnoException (util.js:1028:11) 在TLSWrap.onread (net.js:572:26)代码:'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 ms内返回了响应。
造成这一错误的原因是什么,有什么方法可以解决吗?
发布于 2018-04-02 16:07:40
您是否尝试过在请求中添加timeout选项?当您可以使用本机承诺执行时,为什么要使用Q承诺库?老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) {...});https://stackoverflow.com/questions/49610864
复制相似问题