How do I preserve foreign characterset from REST api when called by C# application

129 views Asked by At

The response from my REST service returns JSON containing the correct Latin characters when I use Postman. When I call the same REST endpoint from my C# api the special characters used in Spanish or Portuguese are replaced with "?".

Correct from Postman REST request: "están compartiendo contraseñas" Incorrect from C# .Net api request : "est?n compartiendo contrase?as"

C#

HttpResponseMessage response = client.PostAsJsonAsync(string.Format("{0}/{1}", baseUri, apiUri), content).Result;
var repl = response.Content.ReadAsStringAsync().Result;

I have also tried to read the response.Content as a byte array and then use UTF8 encoding to preserve the character set.

var replbyte = response.Content.ReadAsByteArrayAsync().Result;
var myUTF8string = Encoding.UTF8.GetString(replbyte);
var myESPstring = Encoding.GetEncoding("iso-8859-1").GetString(replbyte);

These all return the same incorrect text: "est?n compartiendo contrase?as"

I know the REST endpoint is return the correct characters based on the response from Postman. How can I get the correct characterset form by .Net application?

0

There are 0 answers