2013-10-04 20 views

risposta

4

Dopo aver esaminato questo, sembra che l'unico modo sia quello di eseguire manualmente la richiesta DNS. Io uso qualcosa del genere:

var dns = require('dns'), 
    http = require('http'); 

function httpRequest(options, body, done) { 
    var hostname = options.hostname || options.host; 

    if (typeof(body) === 'function') { 
    done = body; 
    body = null; 
    } 

    // async resolve with C-ares 
    dns.resolve(hostname, function (err, addresses) { 
    if (err) 
     return done(err); 

    // Pass the host in the headers so the remote webserver 
    // can use the correct vhost. 
    var headers = options.headers || {}; 
    headers.host = hostname; 
    options.headers = headers; 

    // pass the resolved address so http doesn't feel the need to 
    // call dns.lookup in a thread pool 
    options.hostname = addresses[0]; 
    options.host = undefined; 

    var req = http.request(options, done); 

    req.on('error', done); 

    if (body) 
     req.write(body); 

    req.end(); 
    }); 
} 
Problemi correlati