简体   繁体   中英

Curl does work, https.request() does not, on particular url?

I can happily get the following url below CURL or the browser, but when I try it using node I get an ECONNREFUSED error.

Try this code...

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)
})

I think your code works. I have change the code to test on some urls and log show the requests is ok.

So, i think you could paste the detail error log for deeper analysis !

This is my test code:

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");
    }
  })
})

Console log:

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM