2014-03-14 68 views
0

我可以高興地在CURL或瀏覽器下面獲得以下URL,但是當我嘗試使用節點時,我收到ECONNREFUSED錯誤。Curl確實工作,https.request()不,在特定的網址?

試試這個代碼...

var request = require('request') 

var url = "https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-ash3/t39.2365-6/851565_602269956474188_918638970_n.png" 

var r = request({url:url}, function callback(error, response, body) { 
    console.log("Error:", error) 
    console.dir(r.headers) 
}) 

回答

0

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