I need to convert a byte array to a UTF8 string, and preserve the characters in the array.
Im uploading an image using multipart post. The image is sent along as a UTF8 string. I’ve compared the headers from my app and web browser and the data is the same, apart from one thing.
When it send along the browser, the content contains lots of [] characters, where as my app replaces [] with ?. Which means it’s not preserving the characters as it should. Everything else is the same.
Heres the code I have atm
Byte[] fileOpen = File.ReadAllBytes("C:/pic.jpeg");
postData.AppendLine(System.Text.Encoding.UTF8.GetString(fileOpen));
Any advice?
Why? UTF-8 is a text encoding. Raw binary data should not be encoded but rather sent directly as bytes.
If your transfer protocol doesn’t allow byte transfer, then the usual way is to encode the byes in Base64.