我正在使用 Node.js 的请求模块对地址如下的 api 进行 HTTP GET 调用:http://x.x.xxx.xx:8000/names
但调用返回错误[错误:协议(protocol)无效:null]
。
我的 API 调用如下所示:
request.get({
uri: 'http://x.x.xxx.xx:8000/names'
}, function(err, res, body){
if(err == null){
res.status(200).send(data);
}else{
console.log(err);
}});
注意:我通过“npm config set proxy”和“npm config set https proxy”使用了npm代理。删除它们也不能解决问题。
谢谢
最佳答案
既然这样,工作得很好,我会说问题出在你的代理配置中。
request.get({
uri: 'http://localhost:8000/names'
}, function(err, res, body){
});
试试这个:
npm config set proxy http://usr:pwd@host:port
关于node.js 请求模块给出 http 调用错误 [错误 : Invalid protocol: null],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34964935/