I'm trying to read the HTTP response from a web service, where the content type header is:
Content-Type: text/html; charset=ISO-8859-15
When invoking System.Net.Http.HttpContent.ReadAsStringAsync()
my app fails with System.InvalidOperationException
"The character set provided in ContentType is invalid. Cannot read content as string using an invalid character set."
ISO-8859-15
(Latin-9) though is a valid charset, and the problem seems to be in the incomplete list of charsets hardcoded in .NET (System.Globalization I think).
Is this a bug? Is there another way to read content encoded with this (or any other) charset, other than going lower level into the data stream?
It is the solution for .NET Core. To apply it:
Run dotnet.exe add package System.Text.Encoding.CodePages
Add using System.Text;
and Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)