SecureHttpClient 2.3.5

dotnet add package SecureHttpClient --version 2.3.5
                    
NuGet\Install-Package SecureHttpClient -Version 2.3.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SecureHttpClient" Version="2.3.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SecureHttpClient" Version="2.3.5" />
                    
Directory.Packages.props
<PackageReference Include="SecureHttpClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SecureHttpClient --version 2.3.5
                    
#r "nuget: SecureHttpClient, 2.3.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SecureHttpClient@2.3.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SecureHttpClient&version=2.3.5
                    
Install as a Cake Addin
#tool nuget:?package=SecureHttpClient&version=2.3.5
                    
Install as a Cake Tool

SecureHttpClient

SecureHttpClient is a dotnet cross-platform HttpClientHandler library, with additional security features.

Features

Feature Android iOS Windows
Certificate pinning
TLS 1.2+
HTTP/2
Compression (gzip / deflate / br)
Client certificates
Headers ordering
Cookies

Installation

NuGet

The most recent version is available (and is tested) on the following platforms:

  • Android 8-16 (API 26-36)
  • iOS 26.0
  • .net 9.0

Older versions support older frameworks (but they are not maintained anymore):

  • v2.2: net8.0 (android / ios / windows)
  • v2.1: net7.0 (android / ios / windows)
  • v2.0: net6.0 (android / ios / windows)
  • v1.x: MonoAndroid ; Xamarin.iOS ; NetStandard

Basic usage

Basic usage is similar to using System.Net.Http.HttpClientHandler.

// create the SecureHttpClientHandler
var secureHttpClientHandler = new SecureHttpClientHandler(null);

// create the HttpClient
var httpClient = new HttpClient(secureHttpClientHandler);

// example of a simple GET request
var response = await httpClient.GetAsync("https://www.github.com");
var html = await response.Content.ReadAsStringAsync();

Certificate pining

Usage

After creating a SecureHttpClientHandler object, call AddCertificatePinner to add one or more certificate pinner.

The request will fail if the certificate pin is not correct.

// create the SecureHttpClientHandler
var secureHttpClientHandler = new SecureHttpClientHandler(null);

// add certificate pinner
secureHttpClientHandler.AddCertificatePinner("www.github.com", ["sha256/YH8+l6PDvIo1Q5o6varvw2edPgfyJFY5fHuSlsVdvdc="]);

// create the HttpClient
var httpClient = new HttpClient(secureHttpClientHandler);

// example of a simple GET request
var response = await httpClient.GetAsync("https://www.github.com");
var html = await response.Content.ReadAsStringAsync();

Domain patterns

SecureHttpClient behaves the same as OkHttp: pinning is per-hostname and/or per-wildcard pattern.

To pin both example.com and www.example.com you must configure both hostnames. Or you may use patterns to match sets of related domain names. The following forms are permitted:

  • Full domain name: you may pin an exact domain name like www.example.com. It won't match additional prefixes (abc.www.example.com) or suffixes (example.com).
  • Any number of subdomains: Use two asterisks like **.example.com to match any number of prefixes (abc.www.example.com, www.example.com) including no prefix at all (example.com). For most applications this is the best way to configure certificate pinning.
  • Exactly one subdomain: Use a single asterisk like *.example.com to match exactly one prefix (www.example.com, api.example.com). Be careful with this approach as no pinning will be enforced if additional prefixes are present, or if no prefixes are present.

Note that any other form is unsupported. You may not use asterisks in any position other than the leftmost label.

If multiple patterns match a hostname, any match is sufficient. For example, suppose pin A applies to *.example.com and pin B applies to api.example.com. Handshakes for api.example.com are valid if either A's or B's certificate is in the chain.

Compute the pin

In order to compute the pin (SPKI fingerprint of the server's SSL certificate), you can execute the following command (here for www.github.com host):

openssl s_client -connect www.github.com:443 -servername www.github.com | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -noout -pubkey | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

Cookies and Redirect

SecureHttpClient handles cookies and redirects, but the behavior can differ a bit from one platform to another, because of different implementations in the native libraries used internally.

For strictly identical behavior between platforms, it's recommended to use Flurl on top of SecureHttpClient, and let it handle cookies and redirects.

// create the SecureHttpClientHandler
var secureHttpClientHandler = new SecureHttpClientHandler(null);

// disable redirect and cookies management in this handler
secureHttpClientHandler.AllowAutoRedirect = false;
secureHttpClientHandler.UseCookies = false;

// create the FlurlClient and CookieSession, they will manage redirect and cookies
var httpClient = new HttpClient(secureHttpClientHandler);
var flurlClient = new FlurlClient(httpClient);
var flurlSession = new CookieSession(flurlClient);

// example of a simple GET request using Flurl
var html = await flurlSession
    .Request("https://www.github.com")
    .GetStringAsync();

Advanced usage

For more advanced usage (logging, client certificates, cookies ordering...), have a look into the SecureHttpClient.Test folder for more code examples.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-android35.0 is compatible.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-ios26.0 is compatible.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.3.5 185 11/4/2025
2.3.4 311 10/16/2025
2.3.3 405 9/4/2025
2.3.2 213 9/4/2025
2.3.1 373 11/28/2024
2.3.0 196 11/14/2024
2.2.7 281 11/12/2024
2.2.6 1,121 6/24/2024
2.2.5 733 3/13/2024
2.2.4 226 3/6/2024
2.2.3 209 2/20/2024
2.2.2 243 1/15/2024
2.2.1 285 11/22/2023
2.2.0 471 11/17/2023
2.1.3 821 6/2/2023
2.1.2 3,214 4/25/2023
2.1.1 347 3/3/2023
2.1.0 402 12/19/2022
2.0.1 485 10/27/2022
2.0.0 472 10/25/2022
1.18.8 1,641 10/25/2022
1.18.7 635 7/25/2022
1.18.6 657 3/17/2022
1.18.5 584 11/15/2021
1.18.4 533 10/16/2021
1.18.3 580 6/1/2021
1.18.2 513 5/26/2021
1.18.1 639 2/25/2021
1.18.0 540 2/19/2021
1.17.5 571 2/10/2021
1.17.4 557 2/1/2021
1.17.2 554 1/26/2021
1.17.1 577 1/18/2021
1.17.0 567 1/13/2021
1.16.1 1,748 12/11/2020
1.16.0 623 12/2/2020
1.15.0 620 11/13/2020
1.14.1 653 10/14/2020
1.14.0 832 4/30/2020
1.13.7 804 4/15/2020
1.13.6 916 3/2/2020
1.13.5 684 2/14/2020
1.13.4 686 2/14/2020
1.13.3 720 1/13/2020
1.13.2 732 12/9/2019
1.13.1 747 10/25/2019
1.13.0 726 10/23/2019
1.12.4 868 6/30/2019
1.12.1 775 6/19/2019
1.12.0 851 3/26/2019
1.11.0 1,891 10/10/2018
1.10.0 1,224 6/20/2018
1.9.0 1,374 6/8/2018
1.8.0 1,421 5/25/2018
1.7.0 1,480 4/10/2018
1.6.0 1,323 10/19/2017
1.5.1 3,837 9/27/2017
1.5.0 1,356 7/2/2017
1.4.2 1,405 11/30/2016
1.4.1 1,369 11/25/2016
1.3.0 1,365 10/17/2016