Why do we need res.on ("data" ... specific to POST, even if we do nothing with the data?

Found this code to debug this problem where the following did not work:

var req = http.request(options,function(res){
            // res.on('error',cb(err));
            res.on('end',function(){
                cb();
            });
        });

However, the following worked:

       var req = http.request(options,function(res){
            // res.on('error',cb(err));
            res.on('data',function(chunk){
                //why do we need this?
            });
            res.on('end',function(){
                cb();
            });
        });
+4
source share
3 answers

The variable resis a Readable Stream . If you click the link and scroll down to the 'end' event , you can find the following:

Please note that the event "end" will not occur if the data is not completely destroyed.

Adding an event handler "data", you will use the data.

+4
source

node. , ( TCP). , ( res.read() data res.resume()), , . , , end. res.resume();, .

node v0.10. , data, , . , node v0.10 + - , ( node, ).

+2

function(res) - , 'data' 'end', .

:

"" ; "".

'response' , . , "response", response.read() , "" , .resume(). , "" . , , , " ".

+2

All Articles