我认为你的代码有效。我已更改代码以测试某些 url 并记录显示请求正常。
所以,我认为您可以粘贴详细的错误日志以进行更深入的分析!
这是我的测试代码:
var request = require('request')
var urls = ["https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.2365-6/851565_602269956474188_918638970_n.png",
"https://www.google.com",
"http://nodejs.org/"]
urls.forEach(function(url){
request({url:url}, function callback(error, response) {
console.log("Response for "+url);
if(error){
console.error(error);
}else{
console.log("statusCode: "+response.statusCode);
console.log("body.length: ", response.body.length + " bytes \n");
}
})
})
控制台日志:
Response for https://www.google.com
statusCode: 200
body.length: 44898 bytes
Response for http://nodejs.org/
statusCode: 200
body.length: 6318 bytes
Response for https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.2365-6/851565_602269956474188_918638970_n.png
statusCode: 200
body.length: 722 bytes