I'm getting socket hang up error , when connecting to twitter streaming api with basic authentication using https. I think the error is occurring when doing the authentication.
var https = require("https");
var options = {
host: 'stream.twitter.com',
path: '/1.1/statuses/filter.json?track=bieber',
method: 'GET',
headers: {
"Authorization": "Basic " + new Buffer('UserName' + ":" + 'Password').toString("base64")
}
}; //end of options
var request = https.request(options, function(response){
var body = '';
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.on("data", function(chunk){
var tweet = JSON.parse(chunk);
console.log("Tweet " + tweet.text);
}); // end of data
response.on("end", function(){
console.log("Disconnected!!");
}); // end of end
response.on("error", function(){
console.log("error occured");
}); // end of error
}); // end of request
request.on("error",function(error){
console.log("Error: " + error.message);
}); // end of error
When i try to access this url it works fine.
https://username:password@stream.twitter.com/1.1/statuses/filter.json?track=twitter
Change https.request(options, function(response){ } to https.get(options, function(response){ } Thanks to Darrenlooby on nodejs IRC for pointing it out.
You can use https.request, but make sure you add:
request.end();
where request is the object returned from https.request
See http://nodejs.org/api/https.html#https_https_request_options_callback for an example.
I had the same issue and this fixes it :)