Azure Websites node.js http requests failing

I'm experimenting with the free tier of Azure websites using node.js and git deployment. It's very slick, but I'm trying to make a web service call to Facebook in one of my handlers, and it fails with a 500 internal server error and the following stack trace:

Application has thrown an uncaught exception and is terminated:
Error: connect EADDRNOTAVAIL
at errnoException (net.js:670:11)
at connect (net.js:548:19)
at Socket.connect (net.js:613:5)
at Object.<anonymous> (net.js:77:12)
at new ClientRequest (http.js:1091:25)
at Object.request (http.js:1427:10)
at Object.get (http.js:1432:21)

The code works fine when run locally. Is this a limitation of Azure websites, or is there some other way to make this work? My code looks like this (I'm using express):

app.get('/login', function (req, res) {
  var tokenUrl = 'http://foo.com';
  var body = '';
  http.get(tokenUrl, function (tokenRes) {
    tokenRes.on('data', function (chunk) {
      body += chunk;
    }).on('end', function () {
      res.end(body);
    });
  }).on('error', function (err) {
    console.log('Error fetching site: ' + err.message);
  });
}

So I had this exact same problem but with calling https.get(). Switching from https.get() to https.request() resolved the issue for me. That seems kind of crazy given that http.get() worked fine for me locally. I'm scared to know what's happening here :(

Yes I also encountered this problem. @Steven lckman's answer didn't work for me.


Hey, @Alec Siu, I have tackled the problem. Azure recommend using the request module to issue a http request. See here. But reason were not given. Anyway, it works well.