Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/43.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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
Javascript 错误:connect ECONNREFUSED node.js https.get请求_Javascript_Node.js_Https_Get - Fatal编程技术网

Javascript 错误:connect ECONNREFUSED node.js https.get请求

Javascript 错误:connect ECONNREFUSED node.js https.get请求,javascript,node.js,https,get,Javascript,Node.js,Https,Get,我正在一个小的测试节点项目中运行以下内容 var https = require('https'); var request = https.get('https://example.com/script.json', function(response){ console.dir(response); }); request.on('error', function(){ console.log(err); }); 当我尝试console.dir响应时,我得到以下错误 t

我正在一个小的测试节点项目中运行以下内容

var https = require('https');

var request = https.get('https://example.com/script.json', function(response){
    console.dir(response);
});

request.on('error', function(){
    console.log(err);
});
当我尝试console.dir响应时,我得到以下错误

throw er; // Unhandles 'error' event
Error: connect ECONNREFUSED xxx.xx.xxx.xx:xxx
这是对外部服务器上json文件的简单get请求。我知道该文件存在,所以我不确定为什么会出现上述错误。该文件可以在浏览器中运行,无需身份验证

更新:我编辑了代码。创建了一个承诺并添加了一个
.on('error')…
,以捕获任何问题

现在输出以下内容:

( [Error: connect ECONNREFUSED xxx.xx.xxx.xx:xxx]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: 'xxx.xxx.xxx.xxx',
  port: 443 )

另一台服务器未启动,或未侦听443端口,因此连接被拒绝。
另一个选择是,nodejs应用程序将该示例url解析为与您的pc不同的ip。

感谢@robertklep的帮助,我想出了以下解决方案,允许我使用请求从代理后面连接到HTTPS

const https = require('https');
const request = require('request');

request(
    {
    'url':'https://https://example.com/script.json',
    'proxy':'http://xx.xxx.xxx.xx'
    },
    function (error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(body);
        }
    }
);

好的,除了尝试另一个端口外,我如何解决您建议的第二个可能的问题。在测试中使用direct ip,在机器上更新主机文件,等等…谢谢-但这对我来说没有多大意义。刚开始使用NodeJSAR,您确定您的浏览器没有为您提供缓存版本吗?您使用某种防火墙吗l防止“未经授权”的应用程序进行网络连接的措施?@robertklep-是的,我有一个代理。我有详细信息(端口等)。正如您所说,这可能是问题的原因。我已经设置了
npm config set proxy http
npm config set proxy https
设置。但此错误是由其他原因引起的吗?如果您在代理后,请查看,这会使处理代理服务器变得更容易。