首页 文章

Node.js读取ECONNRESET

提问于
浏览
0

我正在为我的应用程序使用Express.js,并在向adobe analytics API发布请求时收到错误 .

我试图添加 server.timeout 但它没有解决它...

这是错误消息:

错误:在TLSWrap.onread(net.js:572:26)处的exports._errnoException(util.js:1028:11)处读取ECONNRESET代码:'ECONNRESET',错误号:'ECONNRESET',系统调用:'读'

这是失败的代码:

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毫秒的响应 .

这个错误的原因是什么,有什么办法可以解决它吗?

1 回答

  • 0

    您是否尝试在请求中添加 timeout 选项?当你使用本机承诺时,为什么要使用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) {...});
    

相关问题