IP地址,而不是node.js请求模块中的域名
有什么方法可以在node.js请求模块中使用IP地址而不是域名?
我收到以下错误:[错误:无效的URI“192.168.0.101/relay1/on”]
我知道我不应该包括urlscheme(例如:http),所以http:// 192.168.0.101/relay1/on也不会工作。
以下是生成错误的代码:
var arduinoRequestURL = arduinoIp + '/' + modulePrivateName + '/' + req.params.action; request(arduinoRequestURL, function (error, response, body) { console.log(body); console.log(error); console.log(response); });
这里是一个链接到模块: https : //github.com/mikeal/request
是的你可以。 您也必须指定请求的协议。
request('google.com', function (error, response, body) { console.log(body); console.log(error); console.log(response); });
给出[错误:无效的URI“google.com”]
以下是等同的:
request('http://google.com', function (error, response, body) { console.log(body); console.log(error); console.log(response); }); request('http://74.125.236.18', function (error, response, body) { console.log(body); console.log(error); console.log(response); });