2012-07-29 3 views
3

node.js에서 https로 게임하는 동안 응답 데이터를 읽지 못했습니다. 다음은 https 요청에 대한 코드입니다.node.js의 https 응답 데이터 디코딩

https.get(options, function(resp) {      
    console.log(resp.headers)  //working fine 
    resp.on('data', function(d) {   
     console.log(d)    // buffered data; like <Buffer 7b 22 69... 
     process.stdout.write(d); // working fine(prints decoded data in console) 
     var decoded_data=??? }); 
}).on('error', function(e) { 
    console.error(e); 
}); 

하지만, 응답 데이터를 디코딩 할 수있는 방법 & 변수로 쓰기?

답변

6
var decoded_data = d.toString('utf8'); 

또는 이전에 :

resp.setEncoding('utf8'); 

하고 모든 on 이벤트가 당신에게 대신 버퍼의 문자열을 줄 것이다.

+0

d.toString()이 마법을 실행했습니다. 감사합니다 ... – Vivek