Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Net.Http vs Microsoft.Net.Http

I am using ASP.NET Core. I want to use HttpClient but I noticed that there are two NuGet packages being offered. Which one do I use?

  • System.Net.Http
  • Microsoft.Net.Http
like image 748
Muhammad Rehan Saeed Avatar asked Jun 25 '15 14:06

Muhammad Rehan Saeed


People also ask

Is .NET and Microsoft .NET same?

ASP.NET is a web application framework designed and developed by Microsoft. ASP.NET is an open-source and a subset of the . NET Framework and successor of the classic ASP(Active Server Pages).

What is the use of System net http?

The System. Net. Http namespace is designed to provide the following: HTTP client components that allow users to consume modern web services over HTTP.

What is the difference between .NET and .NET standard?

. NET Standard is an API specification that defines, for a given version, what Base Class Libraries must be implemented. . NET Core is a managed framework that is optimized for building console, cloud, ASP.NET Core, and UWP applications.

What are the different .NET platforms?

ASP.NET: The framework that allows you to build web applications and web APIs. Windows Presentation Foundation (WPF): A graphical user interface for Windows desktop applications. Xamarin: The framework for building cross-platform mobile, TV, and desktop applications.


1 Answers

Depends on the version. The old System.Net.Http packages (the 2.0 ones) are legacy packages which are deprecated in favor of Microsoft.Http.Net according to the description:

Legacy package, System.Net.Http is now included in the 'Microsoft.Net.Http' package.

They exist to provide the HttpClient in previous .NET versions and Portable Class libraries. You should use Microsoft.Net.Http in that case.

Since you're using .NET Core, you should use the latest System.Net.Http package (eg. 4.3.3).

Updated for csproj

As of .NET Standard 2.0, the System.Net.HttpClient package is already included and available when you target netstandard2.0. If, for some reason, you still want to reference it for both full .NET and .NET Core, you can add this to your csproj file:

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">     <!-- // HttpClient for full .NET -->     <Reference Include="System.Net.Http" /> </ItemGroup> <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">     <!-- // HttpClient for .NET Core -->     <PackageReference Include="System.Net.Http" Version="4.3.3" /> </ItemGroup> 

If you're using project.json

If your project.json targets both full .NET and .NET Core, you have to add the System.Net.Http assembly to the frameworkAssemblies element. For example:

"frameworks": {   "net451": {     "frameworkAssemblies": {       "System.Net.Http": "4.0.0.0" // HttpClient for full .NET     }   },   "netstandard1.3": {     "dependencies": {       "System.Net.Http": "4.1.0", // HttpClient for .NET Core     }   } } 
like image 134
Henk Mollema Avatar answered Oct 04 '22 21:10

Henk Mollema