Provides a message handler for HttpClient based on the WinHTTP interface of Windows. While similar to HttpClientHandler, it provides developers more granular control over the application's HTTP communication than the HttpClientHandler. Commonly Used Types: System.Net.Http.WinHttpHandler
$ dotnet add package System.Net.Http.WinHttpHandlerThis package provides an HttpMessageHandler implementation backed by Windows HTTP Services (WinHTTP).
While the use of the default HttpClientHandler is highly recommended for applications targeting modern .NET, WinHttpHandler might help migration scenarios by providing an alternative HTTP backend for Windows that works consistently accross .NET Framework and modern .NET.
HttpClient on Windows.WinHttpHandler.using System.Net;
using WinHttpHandler handler = new()
{
ServerCredentials = new NetworkCredential("usr", "pwd")
};
using HttpClient client = new(handler);
using HttpRequestMessage request = new(HttpMethod.Get, "https://httpbin.org/basic-auth/usr/pwd");
using HttpResponseMessage response = await client.SendAsync(request);
Console.WriteLine($"Status: {response.StatusCode}");
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
The main types provided by this library are:
System.Net.Http.WinHttpHandlerSystem.Net.Http.WinHttpHandler is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.