Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
node.js请求模块为http调用提供错误[错误:无效协议:null]_Node.js_Proxy_Request - Fatal编程技术网

node.js请求模块为http调用提供错误[错误:无效协议:null]

node.js请求模块为http调用提供错误[错误:无效协议:null],node.js,proxy,request,Node.js,Proxy,Request,我正在使用node.js的请求模块对地址如下的api进行HTTP GET调用:http://x.x.xxx.xx:8000/names 但是调用返回错误[错误:无效协议:null] 我的api调用如下所示: request.get({ uri: 'http://x.x.xxx.xx:8000/names' }, function(err, res, body){ if(err == null){ res.status(200).send(data); }e

我正在使用node.js的请求模块对地址如下的api进行HTTP GET调用:http://x.x.xxx.xx:8000/names 但是调用返回错误[错误:无效协议: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配置集代理和npm配置集https代理为npm使用了代理。移除它们也不能解决问题


感谢使用request.get,如果要传递选项,必须首先将url指定为字符串,然后是带有选项的字典。该错误可能是由于您在传递字典时感到混淆所致。请尝试使用带有字典参数的请求或请求。get'http://xx.xx.xx.xx:8080/"


供参考的文档:

由于这项功能运行得非常好,我认为问题在于您的代理配置

request.get({
    uri: 'http://localhost:8000/names'
}, function(err, res, body){

});
试试这个:

npm config set proxy http://usr:pwd@host:port

我的HTTP_PROXY环境变量设置不正确

如果您连接到PHP开发服务器,请获取解决方案

不是这样,该请求格式正确。请向我们展示您的代理配置。