0

I'm trying to make a https call in Node JS. Here is the call:

var options = {
    hostname: "https://example.net",
    path: "/abc/test",
    method : 'POST',
    headers: {
        "Content-Type": "application/x-www-form-urlencoded"
    }
};
const req = https.request(options, (res: any) => {
    res.setEncoding('utf8');
    res.on('data', (chunk: any) => {
        // Some Processing on response
    });
});

req.on('error', (error: any) => {
    console.log("Network Error with the HTTP Call. Error: " + error.message);
});

req.write('resource=rs1&query1=sample1&query2=sample2');
req.end();

Hence, I'm expecting a POST call to this url: "https://example.net/abc/test" with the body attached, but to my surprise, I'm always getting this error: Network Error with the HTTP Call. Error: getaddrinfo ENOTFOUND https://example.net https://example.net:443

which implies the call itself is not going through, although the connection seems to be working as I can hit from Postman. Is there anything wrong with the https call?

tanmayghosh2507
  • 773
  • 3
  • 12
  • 31
  • Possible duplicate of [Node.js getaddrinfo ENOTFOUND](https://stackoverflow.com/questions/17690803/node-js-getaddrinfo-enotfound) – Nir Alfasi May 15 '19 at 04:51
  • @alfasin Thanks, followed the previous question. Now I am not getting that error, however status code returned is always 404. Is there any way to get the final URL that's getting called(which I can console log)? Unfortunately, I can't see it in Network tab as the call is made behind internal corp hosted agent, I can only see the logs that i print. – tanmayghosh2507 May 15 '19 at 05:56
  • See: https://stackoverflow.com/questions/21107160/how-to-enable-verbose-log-for-this-node-request-module – Nir Alfasi May 15 '19 at 16:26

0 Answers0