I'm making an HTTP POST request with this:
byte[] postBuffer = Encoding.UTF8.GetBytes(postStr);
So far, this seems working fine but I'm not sure if this will always work, because Encoding.UTF8 means UTF8 WITH BOM. When I create local files with StreamWriter
, always use the default encoding which is the same as new UTF8Encoding(false) in order to write WITHOUT BOM. So wonder if the same is true for calling GetBytes()
method too.
In this case, isn't there any difference between above and below line?
byte[] postBuffer = new UTF8Encoding().GetBytes(postStr);
I tested several times myself but still not sure 100%, so asking here.
The GetBytes
method never returns a stream of bytes prefaced with a BOM.
The BOM can be retrieve by using the GetPreAmble
method, which returns nothing when the encoder is instantiated with false.
See the extensive Remarks section on Microsoft Documentation for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With