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:[email protected]: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);
        }
    });

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章