var text = "Привет"; request("http://site.ru/i.php?t="+text, function(error, res, body){ console.log(body); }); 

Displays: @825B

I.php file:

 <?php error_reporting(E_ERROR); header('Content-type: text/html; charset=utf-8'); echo $_GET["t"]; ?> 
  • And what does console.log(typeof body) display? - Dmitriy Simushev
  • console.log (typeof body): string - Nichh
  • And if you replace echo $_GET['t'] with echo iconv('cp1251', 'utf-8', $_GET['t']); ? - Dmitriy Simushev 1:09 pm
  • Displays "eeeeee." It's not php. I try to send this word “hello” to the telegrams via API. There goes the data in UTF-8. (if there would be another encoding, then an error would occur). In the telegram, I, too, instead of "hello" is displayed "@ 825B" - Nichh
  • Um ... and the JS file itself in what encoding is saved? Similarly, in UTF8? - Dmitriy Simushev

2 answers 2

Always explicitly encode the data.

https://github.com/nodejs/node/issues/1693

The problem is approximately in this piece of code: https://github.com/nodejs/node/blob/v4.x/lib/_http_outgoing.js#L131-L134

As a result, your request is recoded as binary and it turns out such a mess:

 > new Buffer('Привет', 'binary').toString() '\u001f@825B' 

    It should work

     request("http://site.ru/i.php?t=" + encodeURIComponent(text),