Closed Gerappa92 closed 3 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.
FYI @Gerappa92, .NET Core 2.2 is out of support and is no longer receiving security updates or bug fixes. The current supported versions are .NET Core 2.1 and .NET Core 3.1. See https://dotnet.microsoft.com/platform/support/policy/dotnet-core for more information on the support policy.
Yep, looks like we should support this. I assume this still exists in 5.0?
We definitely should support a quoted string here. https://tools.ietf.org/html/rfc7231#section-3.1.1.1
I was able to reproduce it with .NET Core 2.1 (using our LoopbackServer):
System.InvalidOperationException: The character set provided in ContentType is invalid. Cannot read content as string using an invalid character set.
---> System.ArgumentException: '"utf-8"' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
Parameter name: name
at System.Text.EncodingTable.internalGetCodePageFromName(String name)
at System.Text.EncodingTable.GetCodePageFromName(String name)
at System.Text.Encoding.GetEncoding(String name)
at System.Net.Http.HttpContent.ReadBufferAsString(ArraySegment`1 buffer, HttpContentHeaders headers)
However, it works just fine with .NET Core 3.0, 3.1 and with .NET 5. Closing as addressed. Please update to newer version of .NET Core and all should be fine for you. Thanks!
Charset and problem with ReadAsStringAsync
Problem with read a content from external API
General
I'm developing application in .net core 2.2. I use external API and I had a problem with reading a response content as a string. In response in content headers i get ContentType like this: {application/json; charset="utf-8"} where the charset is cause of my problem. When I'm trying to read a content by:
response.Content.ReadAsStringAsync();
I'm getting an exception:
I workarounded this problem by simple replace quots in response header like this:
response.Content.Headers.ContentType.CharSet = response.Content.Headers.ContentType.CharSet.Replace("\"", "");
but i'm not shure that is the best solution. Maybe .net shoudn't have problem with that? Or this external API shouldn't sent charset in quotes?