Get the whole response body when the response is chunked?

前端 未结 7 1004
旧巷少年郎
旧巷少年郎 2020-12-08 06:32

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

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

The problem is that the response is chun

7条回答
  •  渐次进展
    2020-12-08 06:59

    I never worked with the HTTP-Client library, but since it works just like the server API, try something like this:

    var data = '';
    response.on('data', function(chunk) {
      // append chunk to your data
      data += chunk;
    });
    
    response.on('end', function() {
      // work with your data var
    });
    

    See node.js docs for reference.

提交回复
热议问题