ajsie ajsie - 7 months ago 53
HTTP Question

Get the whole response body when the response is chunked?

I'm making a HTTP request and listen for "data":

response.on("data", function (data) { ... })

The problem is that the response is chunked so the "data" is just a piece of the body sent back.

How do I get the whole body sent back?

request.on('response', function (response) {
  var body = '';
  response.on('data', function (chunk) {
    body += chunk;
  response.on('end', function () {
    console.log('BODY: ' + body);