:「=的access_token ...」Node.js的:獲取響應主體從我無法提取POST請求的響應身體Node.js.I'm期待的響應POST請求
應該很簡單,不知道我該怎麼做。 (Node v0.4.3)
這是我的代碼片段。
payload = 'client_id='+client_id + '&client_secret='+ client_secret
+ '&code='+ code
var options = {
host: 'github.com',
path: '/login/oauth/access_token?',
method: 'POST'
};
var access_req = https.request(options, function(response){
response.on('error', function(err){
console.log("Error: " + err);
});
// response.body is undefined
console.log(response.statusCode);
});
access_req.write(payload);
access_req.end();
console.log("Sent the payload " + payload + "\n");
res.send("(Hopefully) Posted access exchange to github");
請注意,數據可能會出現在多個塊中,因此,如果我沒有錯,您必須監聽「結束」事件以確保您具有整個響應主體。 – 2013-01-13 20:02:00
沿着@GuidoGarcía所說的這裏是一個指向更全面的答案,指示如何獲得整個身體的指針。 http://stackoverflow.com/questions/5083914/get-the-whole-response-body-when-the-response-is-chunked – WolfgangCodes 2013-05-23 21:40:41