socket hang up
使用 https 通过基本身份验证连接到 Twitter 流式传输 API 时出现错误。我认为在进行身份验证时会发生错误。
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
当我尝试访问此网址时,它工作正常。
https://username:password@stream.twitter.com/1.1/statuses/filter.json?track=twitter