Aggiornamento - Risposta automatica Vedo che uno deve assicurarsi che il DNS sia stato risolto correttamente dalla macchina, controlla questo codice per assicurarti che l'URL sia raggiungibile nodejs.org/ docs/ultima/api/dns.html # dns.resolvenodejs httprequest con dati - errore getaddrinfo ENOENT
domanda iniziale
sto scrivendo un programma basato nodi, in cui l'utente può chiedere a me di fare un HttpRequest per loro conto {fuori rotta mi forniscono alcuni dati e un metodo per chiamare con} ma ogni volta che faccio un httprequest mi dà un errore
getaddrinfo ENOENT questo è come il mio codice è
function makehttprequest(deviceid, httpaction, httppath,methods, actiondata, callback) {
console.log('we are here with httpaction' + httpaction + ' path ' + httppath + ' method ' + methods + ' action data ' + actiondata);
//do the http post work, get the data, and call the callback function with return data
var options = {
host: httpaction,
port: 80,
path: httppath,
method: methods
};
try {
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
} catch(e) {
console.log('error as : ' + e.message);
}
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
console.log('writing data to request ..');
req.write(actiondata);
console.log('finished writing data to request…');
req.end();
console.log('request ended…');
}
Per lo sviluppo locale utilizzare 127.0.0.1 anziché localhost –