HttpClient is not found in .NET 4.5

2019-01-18 18:15发布

I am trying to use the new HttpClient in .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.

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

4条回答
迷人小祖宗
2楼-- · 2019-01-18 18:35

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

查看更多
ら.Afraid
3楼-- · 2019-01-18 18:44

Add a reference to System.Net.Http:

add ref

查看更多
Fickle 薄情
4楼-- · 2019-01-18 18:48

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

查看更多
We Are One
5楼-- · 2019-01-18 18:53

I encountered the issue when I added a class inside the App_Code folder having this HttpClient called in one of my function. Upon spending countless hours I found that the Build Action under Properties for my class is set to Content.

Changing this Build Action to Compile fixed the problem.

查看更多
登录 后发表回答