I think the problem is that the server returns the wrong charset name in header. Instead charset=utf-8
it set charset=utf8
.
And in the point of deserialization, the HttpClient
(RestEase use it) does not understand what encoding to use.
To solve the problem, you need to add a new provider that will point to the usual UTF8 encoding.
You should add code at "global" level (e.g. Main
method):
EncodingProvider provider = new CustomUtf8EncodingProvider();
Encoding.RegisterProvider(provider);
And class, witch return UTF8 encoding for wrong charset name:
public class CustomUtf8EncodingProvider : EncodingProvider
{
public override Encoding GetEncoding(string name)
{
return name == "utf8" ? Encoding.UTF8 : null;
}
public override Encoding GetEncoding(int codepage)
{
return null;
}
}
I check it like this
EncodingProvider provider = new CustomUtf8EncodingProvider();
Encoding.RegisterProvider(provider); //If comment this row - you get exception "'UTF8' is not a supported encoding name...", if uncomment - it works good
Console.WriteLine(Encoding.GetEncoding("utf8").GetString(new byte[]{0x31,0x32,0x33}));
Note
It works in .net 4.6 or higher only