更新 - 通過自我回復 我看到一個人必須確保從計算機上正確解析DNS,檢查此代碼以確保url可到達nodejs.org/文檔/最新/ API/dns.html#dns.resolvenodejs httprequest與數據 - 獲取錯誤getaddrinfo ENOENT
原始的問題
我寫的基於程序的節點,其中,用戶可以要求我做一個HTTPRequest,代表他們{偏離航向他們爲我提供了一些數據,並與方法調用}但每次我做一個HTTPRequest,一次給我一個錯誤
的getaddrinfo ENOENT 這是我的代碼看起來
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…');
}
對於本地開發,請使用127.0.0.1而不是本地主機 – 2016-06-23 06:00:04