NODE JS Code:

var data = ''; sslserv.on('request', function(request, response) { if ((request.method=='POST' || request.method=='GET') && request.url.indexOf('socket')==-1){ var data_arr = []; request.on('data', function(chunk) { data = chunk.toString(); console.log(data); }); request.on('end', function() { if (!data){ response.write('It\'s Work!'); response.end(); } }); } }); 

Here is the PHP submission code:

 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://127.0.0.1:8888"); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); result = curl_exec($ch); curl_close($ch); 

When a request with a length of more than 900-1000 characters arrives at the node through PHP_CURL, not the information that was sent to the console! The line may appear an extra space or a line break ...

Everything would be okay, but I parse this line through JSON.parse and eventually the error crashes! )) I sinned on the function but after I paid attention to the fact that the request data is distorted!

Why? How to fix ?

  • It seems to me that the point is that you are trying to output each chunk with a separate call to console.log, and if you collect chunks on one line before outputting, everything will work. - Fynivx
  • Maybe I misunderstood you, but this is a single request! and about outputting one request body to the console! The bottom line is that if the line is a little less - it is issued correctly! How to add a few characters to it - it is not displayed correctly ... Maybe the node itself divides the request into several pieces ??? - L. Aleksandr
  • one
    For a single request, the request.on ("data") handler can be called as many times as desired, and it is the number of times that console.log is called in you, not just one. And the node is not suitable here. The point is the size of the request and the network settings / capabilities. - Fynivx
  • It looks like a reality! Then the situation becomes clearer)) so it’s necessary to somehow catch and gather the request data into one .. with the help of this handler is it possible? - L. Aleksandr
  • You have some kind of porridge. data should not be a global variable. It must be declared inside the request handler. And data_arr is not used at all - Alexey Ten

0