2013-02-23 2 views
3

https를 사용하는 기본 인증으로 twitter streaming api에 연결할 때 socket hang up 오류가 발생합니다. 인증을 할 때 오류가 발생한다고 생각합니다.twitter api에 연결할 때 Node.js 소켓 끊기 오류가 발생했습니다.

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 

이 URL에 액세스하려고하면 정상적으로 작동합니다. 그것을 지적 nodejs IRC에 Darrenlooby에

https://username:[email protected]/1.1/statuses/filter.json?track=twitter 
+1

이 오류는 NodeJS 0.8.20에 포함되어있다 (당신이 https://raw.github.com/joyent/node/v0을에서 볼 수있다. 8.20/변경 로그). 소켓 연결이 끝날 때 발생합니다. 이전 노드 버전과 완벽하게 작동하는 코드로이 오류를 실험했습니다. – sgmonda

답변

5

변경 https.request(options, function(response){ }https.get(options, function(response){ }에게 감사드립니다.

+0

이유를 아는 사람이 있습니까? – LeeGee

관련 문제