我看到必须确保从计算机正确解析了DNS,请查看节点文档以确保域是可解析的。
我正在编写一个基于节点的程序,用户可以要求我代表他们执行一次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…'); }
我已经看到,当您的主机(您通过httpaction传递)前面有方案(即“ http://”)时,就会发生这种情况。您的主机必须严格属于“ www.google.com”之类的域名,而不是“ http://www.google.com ”或“ www.google.com/hello-world”或“ http://www.google.com” / hello- world ”。
保留它只是域。
这是一个示例:http : //allampersandall.blogspot.com/2012/03/nodejs-http-request- example.html