Get the whole response body when the response is chunked?

前端 未结 7 998
旧巷少年郎
旧巷少年郎 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:44

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

提交回复
热议问题