Skip to content

Commit a71ffcb

Browse files
committed
提高GetEncoding的兼容性
1 parent 9f51ffa commit a71ffcb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

WebApiClientCore/System.Net.Http/HttpContentExtensions.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,18 @@ public static async Task<byte[]> ReadAsByteArrayAsync(this HttpContent httpConte
8888
public static Encoding GetEncoding(this HttpContent httpContent)
8989
{
9090
var charSet = httpContent.Headers.ContentType?.CharSet;
91-
if (string.IsNullOrEmpty(charSet) || charSet == Encoding.UTF8.WebName)
91+
if (string.IsNullOrEmpty(charSet) == true)
9292
{
9393
return Encoding.UTF8;
9494
}
95-
return Encoding.GetEncoding(charSet);
95+
96+
var span = charSet.AsSpan().TrimStart('"').TrimEnd('"');
97+
if (span.Equals(Encoding.UTF8.WebName, StringComparison.OrdinalIgnoreCase))
98+
{
99+
return Encoding.UTF8;
100+
}
101+
102+
return Encoding.GetEncoding(span.ToString());
96103
}
97104
}
98105
}

0 commit comments

Comments
 (0)