Which Httpclient is better in WinRT development?

2019-09-02 20:17发布

问题:

In my progress of winRt development i find that I can use both of the two HttpClient:

System.Net.Http.HttpClient
windows.web.http.httpclient

What's the difference and how can i choose one?

回答1:

You should be using

windows.web.http.httpclient

for WinRT development as stated here.

Note The System.Net.Http and System.Net.Http.Headers namespace might not be available in future versions of Windows for use by Windows Store apps. Starting with Windows 8.1 and Windows Server 2012 R2, use Windows.Web.Http.HttpClient in the Windows.Web.Http namespace and the related Windows.Web.Http.Headers and Windows.Web.Http.Filters namespaces instead for Windows Runtime apps.

Here is the link from msdn.



回答2:

#1 is a .net function so it can only be used from .net languages (C# and VB.net), while #2 is from the Windows Runtime which means it can also be used from javascript store apps.

If you're using C# use whatever you like. My guess is #1 is calling #2