1

The response received is the following:

'UTF8' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
Parameter name: name
The character set provided in ContentType is invalid. Cannot read content as string using an invalid character set.
Dot NET
  • 4,891
  • 13
  • 55
  • 98

1 Answers1

2

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

Anton Gorbunov
  • 1,414
  • 3
  • 16
  • 24