Node.js http end end event?

I used this piece of code to send some HTTP requests and receive data, and it worked fine. I recently updated apache and php to the latest versions, as well as node.

And the close event stopped firing. I also tried to โ€œfinishโ€ and โ€œfinishโ€, none of this works.

I need to know when the answer is complete, so I can start processing the data, this usually happens in several pieces. Can you guys help?

var req = http.request(options, function(res) { res.on('data', function (chunk) { if(chunk != null && chunk != "") { dataString += chunk; c } }); }); req.on('close', function () { //tadaa it is finished, so we can process dataString }); req.write(post_data); req.end(); 

Current versions: Apache 2.4, PHP 5.4 node 0.10.9

Perhaps there are some Apache configuration settings that prevent the connection from being closed?

PS I donโ€™t think this is Apache, though .. I tried google.com with the same result .. quite strange ... Does anyone have an example of working code? (upload big data and know when it ended)

+4
source share
1 answer

You should expect an end response event, not a request.

eg.

 res.on('end', function () { // now I can process the data }); 
+8
source

Source: https://habr.com/ru/post/1484206/


All Articles