添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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)
  •