ajsie ajsie - 1 year ago 100
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?

Answer Source
request.on('response', function (response) {
  var body = '';
  response.on('data', function (chunk) {
    body += chunk;
  response.on('end', function () {
    console.log('BODY: ' + body);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download