我覺得你的代碼工作。我已經更改了代碼以在一些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