Monday 10 April 2017

read ECONNRESET error in nodejs

I extracted this piece of code from nodejs documentation Link, but when i run using my nodejs server It gave me this error. Some people in stack overflow had the same error, but I didn't find solution.

  var postData = querystring.stringify({
    'msg' : 'Hello World!'
  });

  var options = {
    host: 'westus.api.cognitive.microsoft.com',
    port: 443,
    path: '/vision/v1.0/ocr?language=pt&detectOrientation=true',
    method: 'POST',
    headers: {'Ocp-Apim-Subscription-Key': 'API_KEY',
      'Content-type': 'application/json'
    }
  };
  var req = http.request(options, (res) => {
    console.log(`STATUS: ${res.statusCode}`);
    console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
    res.setEncoding('utf8');
    res.on('data', (chunk) => {
      console.log(`BODY: ${chunk}`);
    });
    res.on('end', () => {
      console.log('No more data in response.');
    });
  });

  req.on('error', (e) => {
    console.log(`problem with request: ${e.message}`);
  });

  // write data to request body
  req.write(postData);
  req.end();



via Rodolfo Oliveira

No comments:

Post a Comment