node.js 请求模块为 http 调用提供错误 [错误:无效协议:空] [英] node.js request module giving error for http call [Error: Invalid protocol: null]
问题描述
我正在使用 node.js 的请求模块对具有如下地址的 api 进行 HTTP GET 调用:http://xxxxx.xx:8000/names
但调用返回错误[错误:无效的协议:空]
.
I am using request module for node.js to make HTTP GET call to an api having address like: http://x.x.xxx.xx:8000/names
but the call is returning an error [Error: Invalid protocol: null]
.
我的 api 调用如下所示:
My api call looks like this:
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 使用了代理.删除它们也不能解决问题.
Note: I have used proxies for npm through "npm config set proxy" and "npm config set https proxy" . Removing them is also not solving the problem.
谢谢
推荐答案
既然这样,工作得很好,我会说问题出在你的代理配置上.
Since this, works perfectly fine, I'll say that the problem is in your proxy config.
request.get({
uri: 'http://localhost:8000/names'
}, function(err, res, body){
});
试试这个:
npm config set proxy http://usr:pwd@host:port
这篇关于node.js 请求模块为 http 调用提供错误 [错误:无效协议:空]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!