'await response.Content.ReadAsAsync<ReCAPTCHAVerificationResponse>()' 的 .net5 替代品是什么

What is the .net5 replacement for 'await response.Content.ReadAsAsync<ReCAPTCHAVerificationResponse>()'

https://github.com/sample-by-jsakamoto/Blazor-UseGoogleReCAPTCHA 是 Blazor 的 reCaptcha V2 示例实现。它包含一个名为 SampleApi 的 class,它又包含以下无法编译的行: var verificationResponse = await response.Content.ReadAsAsync<ReCAPTCHAVerificationResponse>();

我在某处找到了使用建议: var verificationResponse = await JsonSerializer.DeserializeAsync<ReCAPTCHAVerificationResponse>(await response.Content.ReadAsStreamAsync()); 但它没有用。它编译但没有提供可用的验证响应。

我通过安装 Microsoft.AspNet.WebApi.Client 让它工作,但它已被弃用。看来一定有更好的办法。

如果您正在使用 Newtonsoft.Json,您正在寻找类似

的东西
var content = await response.Content.ReadAsStreamAsync();
var response = JsonConvert.DeserializeObject<ReCAPTCHAVerificationResponse>(content);

如果您使用的是 System.Text.Json(Microsoft 的风格,并且在大多数情况下由他们推荐 Newtonsoft.Json)

var response = response.Content.ReadAsAsync<ReCAPTCHAVerificationResponse>();

但是,这不是 Blazor 或 .NET 5 独有的。