我可以帮助您翻译以下内容:
每当我点击增量计数时,没有任何反应,并且对GetWeb的服务调用在GetAsync调用中被卡住。
更新: 如果我在Chrome的WASM调试器中调试WebCrawler服务,则请求正在进行。
我正在制作一个客户端 Blazor 应用程序,目标是 Blazor 3.0.0-preview4-19216-03。
Razor 页面:
@page "/counter"
@using BlazorServiceTest
@inject IWebCrawlServiceAsync WebCrawler
<h1>Counter</h1>
<p>Current count: @debug</p>
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
@functions {
string debug = "";
async void IncrementCount()
{
debug = await WebCrawler.GetWeb();
}
}
依赖注入:
using BlazorServiceTest;
using Microsoft.AspNetCore.Components.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace BlazorServicesTest
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IWebCrawlServiceAsync, WebCrawlServiceAsync>();
}
public void Configure(IComponentsApplicationBuilder app)
{
app.AddComponent<App>("app");
}
}
}
该服务:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace BlazorServiceTest
{
public interface IWebCrawlServiceAsync
{
Task<string> GetWeb();
}
public class WebCrawlServiceAsync : IWebCrawlServiceAsync
{
private HttpClient _client;
public WebCrawlServiceAsync(HttpClient client)
{
_client = client;
}
public async Task<string> GetWeb()
{
var response = await _client.GetAsync("https://postman-echo.com/response-headers?foo1=bar1&foo2=bar2");
var result = await response.Content.ReadAsStringAsync();
return result;
}
}
}
每当我点击增量计数时,没有任何反应,并且对GetWeb的服务调用在GetAsync调用中被卡住。
更新: 如果我在Chrome的WASM调试器中调试WebCrawler服务,则请求正在进行。
但是响应部分为空:
HttpClient
?还是它会自动添加? - Nkosiasync void
有关。我正在阅读更多资料以确保。 - Nkosi