I have the following code in C# that converts a string from one encoding to the other and send the response over http.
Everything in the code works fine. I'm just a bit confused
When I return this over http it gets converted into a text representation. I thought this would just send the raw byte array?
Why is it converted? Should I never try and send a raw byte array or is there a case for that when communicating over http? Or is a text representation and a application/octet-stream
the way to send binary data over http?
byte[] fromBytes = fromEncoding.GetBytes(body);
byte[] toBytes = Encoding.Convert(fromEncoding, toEncoding, fromBytes);
var response = req.CreateResponse(HttpStatusCode.OK);
MemoryStream ms = new MemoryStream(toBytes);
response.Content = new StreamContent(ms);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return response;