byte[] WriteBuffer = Encoding.UTF8.GetBytes(Str); Console.WriteLine(Encoding.UTF8.GetString(WriteBuffer)); client.GetStream().Write(WriteBuffer, 0, WriteBuffer.Length); 

Here is the code. It is verified that WriteBuffer is decoded normally, but a string is sent to the browser, ~ 10-20 characters less than the string. Previously, the encoding was ASCII, and everything worked well. What could be the problem?

UPD: There are no such problems with the English text

enter image description here

UPD2: Screenshot console output Console.WriteLine (Encoding.UTF8.GetString (WriteBuffer)); enter image description here

  • try to call Flush () for stream after recording - Umed
  • @Umed, did not help = ( - Fexolm
  • Is str exactly a string in utf? - Umed
  • Is the Content-Length correctly calculated by the size of the data being sent, and not by the size of the string? - vitidev
  • @vitidev, perhaps there is an error here, now I'll take a look - Fexolm

2 answers 2

As vitidev correctly noted, the error was that the Content-Length calculated from the length of the string, and not from the size of the data.

    I would venture to suggest that you forgot using :

     using (var ns = client.GetStream()) { ns.Write(WriteBuffer, 0, WriteBuffer.Length); } 
    • I'm afraid not, it does not help either. I noticed that with the English text everything is displayed normally - Fexolm
    • @Artem: And if the line is: "english text 1 русский текст english text 2" ? - VladD
    • <! DOCTYPE html> <html lang = "en" xmlns = " w3.org/1999/xhtml "> <head> <meta charset = "utf-8" /> <title> english text 1 russian text english text 2 < / title> </ head> <body> <h1> english text 1 Russian text english text 2 </ h1> <p> english text 1 Russian text en - Fexolm
    • if you write without "Russian text", then the markup is normal - Fexolm
    • @Artem: Okay, and what encoding do you give in the http response? - VladD