节点 Js 问题:getaddrinfo ENOTFOUND [英] Node Js Issue: getaddrinfo ENOTFOUND

查看:60
本文介绍了节点 Js 问题:getaddrinfo ENOTFOUND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个节点应用程序来向外部 URL 发出 https 请求.我支持公司代理并且我已经设置了

I am writing a node application to make a https request to an external URL. I am behind a corporate proxy and I have set

>npm config set proxy http://proxy.sample.example.org:8080
>npm config set https-proxy http://proxy.sample.example.org:8080

我可以毫无问题地下载节点依赖项.但是,当我尝试访问外部 URL 时,它会引发以下错误.

I am able to download the node dependencies without issues. But, When I try to hit the external URL, it throws up the following error.

    { Error: getaddrinfo ENOTFOUND example.net example.net:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
    code: 'ENOTFOUND',
    errno: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'example.net',
    host: 'example.net',
    port: 443 }

这同样适用于 google.com.代码如下.

The same applies to even google.com. Code is as below.

var request = require('request');
request.get(   
    {
    url : connUrl,//This is set to be https://example.net
    },function (error, response, body) {
       //Print response code
        console.log(body);
        console.log(error);
      });

有人可以建议我哪里出错了

Can someone please suggest where I am going wrong

推荐答案

对于 Requests 模块,您可以使用 proxy 选项设置代理.尝试这样的事情,

For Requests module, you can set the proxy using the proxy options. Try something like this,

request.get({
      proxy: "proxy",
      url : connUrl,//This is set to be https://example.net
    },function (error, response, body) {
       //Print response code
        console.log(body);
        console.log(error);
});

或者,您也可以设置 http_proxy 和/或 https_proxy 环境变量.

Alternatively you could also set the http_proxy and/or https_proxy environment variables.

这篇关于节点 Js 问题:getaddrinfo ENOTFOUND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆