[英]IServiceCollection does not contain a defintion for AddHttpClient
I am trying to use HttpClient in my .net core 2.0 project and for that I have injected HttpClient in my controller. 我试图在我的.net核心2.0项目中使用HttpClient,为此我已经在我的控制器中注入了HttpClient。 But when I am trying to configure httpclient in my startup.cs I am getting this error: "IServiceCollection does not contain a defintion for AddHttpClient". 但是,当我尝试在我的startup.cs中配置httpclient时,我收到此错误:“IServiceCollection不包含AddHttpClient的定义”。 I have already referenced using Microsoft.AspNetCore.Http;
我已经using Microsoft.AspNetCore.Http;
引用了using Microsoft.AspNetCore.Http;
and using Microsoft.Extensions.DependencyInjection;
并using Microsoft.Extensions.DependencyInjection;
and here is what I am trying to do: 这就是我要做的事情:
services.AddHttpClient<TestController>();
It's working fine in other project with same namespaces but here I am getting the error. 它在具有相同命名空间的其他项目中工作正常,但在这里我得到了错误。 Any help? 有帮助吗?
您需要从NuGet安装Microsoft.Extensions.Http。
Aah, I have found the solution. 啊,我找到了解决方案。 I think services.AddHttpClient
work with .net core 2.1. 我认为services.AddHttpClient
与.net核心2.1一起工作。 So I updated my .net core version to 2.1 and updated the microsoft packages to 2.1 and it starts working. 所以我将.net核心版本更新为2.1并将微软软件包更新为2.1并开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.