nodejs request get请求外部接口,报错请求超时Error: connect ETIMEDOUT 220.181.38.149:80

nodejs request get请求外部接口,报错请求超时问题,一直以为是写法不对,后来是发现公司网设置了代理,程序中同样需要设置代理

var reqUrl = request(url,{'proxy':'http://username:password@url:port'});//这是get方式

request('http://www.baidu.com',{'proxy':'http://xiaoxian:12345678@proxy.gongsi.com:8080'},function(error, response, body){


        if (!error && response.statusCode == 200) {
            console.log(body) // Show the HTML for the baidu homepage.
            res.send(body);
        }else{
            console.log("出错了"+error);
        }
    });

 

引用\[1\]:npm ERR! A complete log of this run can be found in: npm ERR! D:\nodejs\node_cache\_logs\2022-11-18T01_42_13_930Z-debug.log 。 引用\[2\]:npm WARN using --force I sure hope you know what you are doing. npm ERR! errno ETIMEDOUT npm ERR! network request to http://registry.npmjs.org/html2canvas failed, reason: connect ETIMEDOUT 104.16.17.35:80 npm ERR! network This is a problem related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network settings. npm ERR! network npm ERR! network If you are behind a proxy, please make sure that the npm ERR! network 'proxy' config is set properly. See: 'npm help config' 。 引用\[3\]:然后尝试 ping github.com 超时了 之后去 http://ping.chinaz.com/https://github.com 找到一个韩国的 host 修改本地 host 文件 52.78.231.108 github.com 。 问题: 我在使用npm时遇到了一些错误,如何解决? 回答: 根据你提供的引用内容,你在使用npm时遇到了一些错误。首先,你遇到了一个连接超时的错误,可能是由于网络连接问题导致的。这可能是你处于代理后面或者网络设置有问题所致。如果你处于代理后面,请确保npm的'proxy'配置正确设置。你可以通过运行'npm help config'来获取更多信息。\[2\]另外,你还尝试了ping github.com,但是超时了。为了解决这个问题,你去了一个网站并找到了一个韩国的host,并将其添加到本地的host文件中。这可能是为了解决与github.com的连接问题。\[3\]如果你遇到了其他错误,你可以查看完整的日志文件,其中包含了更详细的错误信息。\[1\] #### 引用[.reference_title] - *1* *2* [npm安装报错: errno ETIMEDOUT network request toXXX failed, reason: connect ETIMEDOUT](https://blog.csdn.net/weilikk/article/details/127916162)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [记一次npm install 报RequestError: connect ETIMEDOUT 20.205.243.166:443和RequestError: socket hang up](https://blog.csdn.net/weixin_42634260/article/details/121330269)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值