请问如何在 .NET Core console application 中通过 dependency injection 的方式使用 HttpClient?
通过下面的代码实现了
var host = Host.CreateDefaultBuilder() .ConfigureServices(services => { services.AddHttpClient(); }).Build(); var httpClient = host.Services.GetRequiredService<HttpClient>();