在响应被分块时获取整个响应主体? [英] Get the whole response body when the response is chunked?

查看:109
本文介绍了在响应被分块时获取整个响应主体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在发出HTTP请求并收听数据:

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.

如何将全身送回?

推荐答案

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

这篇关于在响应被分块时获取整个响应主体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆