Node.js HTTP request not returning full response

前端 未结 1 385
清酒与你
清酒与你 2020-12-28 19:13

I\'m making a HTTP request using Node\'s http module, but on data, the chunk returned doesn\'t seem to content the full request response.

相关标签:
1条回答
  • 2020-12-28 19:43

    you should also listen for the 'end' event

    req.on('response', function (response) {
    
        var data = "";
    
        response.on('data', function (chunk) {
            console.log(chunk);
            data += chunk;
        });
    
        response.on('end', function(){
            callback(data);
        })
    
    });
    
    0 讨论(0)
提交回复
热议问题