nodejs request get请求外部接口,报错请求超时Error: connect ETIMEDOUT 220.181.38.149:80
转载声明:
本文为摘录自“csdn博客”,版权归原作者所有。
温馨提示:
为了更好的体验,请点击原文链接进行浏览
摘录时间:
2020-06-03 14:06:09
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);
}
});