0
it always gives :
Error: getaddrinfo ENOTFOUND <hostname without http or https>
    at errnoException (dns.js:44:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:94:26)
STATUS: undefined

My code is as follows:-

var Http = require('https');
var str = "";
var options = {
    hostname: '<host name without http or https>',
    path: '<path>',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json;charset:utf-8',
        'Content-Length': payload.length,
        'User-Agent': 'Node.js/0.12.7',
        'Proxy-Connections': 'keep-alive'
    }
};

var req = Http.request(options, function(res) {
    res.setEncoding('utf-8');
    res.on('data', function(response) {
        str += response;
    });
    res.on('end', function() {
        return exits.success(str);
    });
});
req.on('error', function(e) {
    console.log('STATUS: ' + e.statusCode);
    exits.error('problem with request: ' + e.message);
});
req.write(payload);
req.end();

I have already tried following:- - setting proxy and https-proxy
- removing http or https from host name

Please help me resolving this issue.

2
  • You need to fill in the actual hostname and path in the options object. Commented Aug 21, 2015 at 0:31
  • Thanks for your reply, but I tried that already but not helped anything. Commented Aug 24, 2015 at 22:26

1 Answer 1

3

Set the agent parameter in your request option with so it can cope with the corporate proxy.

var Http = require('https');
var HttpsProxyAgent = require('https-proxy-agent');

// Use the environment variables or set proxy server manually.
var proxyServer = process.env.http_proxy ||
                  process.env.HTTP_PROXY ||
                  process.env.https_proxy ||
                  process.env.HTTPS_PROXY ||
                 'https://168.63.76.32:3128';

var options = {
    agent: new HttpsProxyAgent(proxyServer ),       // <-- proxy agent
    hostname: '<host name without http or https>',
    path: '<path>',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json;charset:utf-8',
        'Content-Length': payload.length,
        'User-Agent': 'Node.js/0.12.7',
        'Proxy-Connections': 'keep-alive'
    }
};

See proxy agent documentation for more info:

https://www.npmjs.com/package/http-proxy-agent

https://www.npmjs.com/package/https-proxy-agent

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.