C# 在 .NET 4.5 中找不到 HttpClient

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16326522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 00:45:41  来源:igfitidea点击:

HttpClient is not found in .NET 4.5

c#.netasynchronoushttpclient.net-4.5

提问by Joan Venge

I am trying to use the new HttpClientin .NET 4.5, but Visual Studio complains that it doesn't exist. I have System.Net, but when I type System.Net.Http, it complains for that too.

我试图HttpClient在 .NET 4.5 中使用新的,但 Visual Studio 抱怨它不存在。我有System.Net,但是当我输入时System.Net.Http,它也会抱怨。

Am I supposed to download a new distributable for this class?

我应该为这个类下载一个新的可分发文件吗?

采纳答案by ulrichb

Add a reference to System.Net.Http:

添加对以下内容的引用System.Net.Http

add ref

添加参考

回答by The Sammie

I had the same problem. After some digging around, i found you had to install this packageand then add the reference to System.Net.Httpfor it to not complain!

我有同样的问题。经过一番挖掘,我发现你必须安装这个包,然后添加System.Net.Http对它的引用才不会抱怨!

回答by johnbuen

I encountered the issue when I added a class inside the App_Codefolder having this HttpClientcalled in one of my function. Upon spending countless hours I found that the Build Actionunder Propertiesfor my class is set to Content.

当我在App_Code文件夹中添加一个类时遇到了这个问题,这个类在HttpClient我的一个函数中被调用。花了无数个小时后,我发现我班级的Build ActionunderProperties设置为Content.

Changing this Build Actionto Compilefixed the problem.

更改此设置Build ActionCompile解决问题。

回答by WindyHen

Start using vs2017, and encounter same problem, when creating Native + PCL, couldn't find the HttpClient, going to Nuget and get Microsoft.Net.Http solve my problems. enter image description here

开始使用vs2017,遇到同样的问题,在创建Native + PCL时,找不到HttpClient,去Nuget获取Microsoft.Net.Http解决我的问题。 在此处输入图片说明