我新建了一个 西装外套 应用程序,我想通过 访问 URL HttpClient
我遇到了这个错误
'HttpClient' does not contain a definition for 'GetFromJsonAsync' and no accessible extension method 'GetFromJsonAsync' accepting a first argument of type 'HttpClient' could be found (are you missing a using directive or an assembly reference?) [BlazorApp]csharp(CS1061) ,
这是我的代码
@inject HttpClient Http
<h1>@name</h1>
@code {
private string name;
protected override async Task OnInitializedAsync()
{
name = await Http.GetFromJsonAsync<string>("api/");
}
}
最佳答案
您需要添加以下 using 指令:
using System.Net.Http.Json;
GetFromJsonAsync
is an extension method ,不属于 HttpClient
本身。
关于c# - “HttpClient”不包含 'GetFromJsonAsync' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64134706/