Asp.net core 为什么Blazor中缺少HttpResponseMessage.IsSuccessStatusCode属性?
我总是像Microsoft所说的那样得到HTTP的响应(),而且效果很好:Asp.net core 为什么Blazor中缺少HttpResponseMessage.IsSuccessStatusCode属性?,asp.net-core,.net-core,blazor,blazor-server-side,Asp.net Core,.net Core,Blazor,Blazor Server Side,我总是像Microsoft所说的那样得到HTTP的响应(),而且效果很好: var request = new HttpRequestMessage(HttpMethod.Get,string.Format(NavigationManager.Uri + "Callback/JSInitialise")); var client = _clientFactory.CreateClient(); var response = client.Se
var request = new HttpRequestMessage(HttpMethod.Get,string.Format(NavigationManager.Uri + "Callback/JSInitialise"));
var client = _clientFactory.CreateClient();
var response = client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
string Content = await response.Content.ReadAsStringAsync();
}
现在我在Blazor中使用它:
@inject IHttpClientFactory _clientFactory
@using SI_Customservice.Pages.Componets
@using System.Net.Http
protected override async Task OnInitializedAsync()
{
var request = new HttpRequestMessage(HttpMethod.Get, string.Format(NavigationManager.Uri + "Callback/JSInitialise"));
var client = _clientFactory.CreateClient();
var response = client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
string Content = await response.Content.ReadAsStringAsync();
}
}
同时,Visual Studio报告此错误:
如前所述,它位于System.Net.Http
的名称空间中,我使用了它
为什么Visual Studio仍然无法识别它?您需要等待客户端。SendAsynccall@MarkPM好!它马上就起作用了!这有什么问题?它返回一个
任务
而不是HttpResponseMessage
@aguafrommars很好,谢谢。您需要等待客户端。SendAsynccall@MarkPM好!它马上就起作用了!这有什么不对?它返回一个任务
而不是HttpResponseMessage
@aguafrommars很好,谢谢。