Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用https.request分块传输编码的NodeJ_Node.js_Https_Buffer - Fatal编程技术网

Node.js 使用https.request分块传输编码的NodeJ

Node.js 使用https.request分块传输编码的NodeJ,node.js,https,buffer,Node.js,Https,Buffer,我向一个API发出GET请求,该API以传输编码:chunked响应。 这是一个https请求,我将('data')侦听器附加到它,然后将响应添加到一个数组中 根据响应,大约有5个块传入,每个块都是缓冲区。当我对数组进行压缩并尝试将其转换为字符串时,我得到了一个奇怪的解码回复,看起来是编码的。我想这可能是因为请求是HTTPS,但我不确定,下面是我解码它的代码 response.on('data', (data) => { // Data is sen

我向一个API发出GET请求,该API以
传输编码:chunked
响应。 这是一个https请求,我将('data')侦听器附加到它,然后将响应添加到一个数组中

根据响应,大约有5个块传入,每个块都是缓冲区。当我对数组进行压缩并尝试将其转换为字符串时,我得到了一个奇怪的解码回复,看起来是编码的。我想这可能是因为请求是HTTPS,但我不确定,下面是我解码它的代码

response.on('data', (data) => {
                    // Data is sent in binary chunks, let's add them up to an array
                    binaryDataArray.push(data)
                }).on('end', () => {
                    const buffer = Buffer.concat(binaryDataArray);

                    try{
                        const formattedData = JSON.parse(buffer.toString('utf8'));
                        resolveRequest(formattedData);
                    }catch(error){
                        setTimeout(makeRequest, 5000);
                    }
                });
任何帮助都将不胜感激