TlsClient.Native 0.4.6

dotnet add package TlsClient.Native --version 0.4.6
                    
NuGet\Install-Package TlsClient.Native -Version 0.4.6
                    
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="TlsClient.Native" Version="0.4.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TlsClient.Native" Version="0.4.6" />
                    
Directory.Packages.props
<PackageReference Include="TlsClient.Native" />
                    
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 TlsClient.Native --version 0.4.6
                    
#r "nuget: TlsClient.Native, 0.4.6"
                    
#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 TlsClient.Native@0.4.6
                    
#: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=TlsClient.Native&version=0.4.6
                    
Install as a Cake Addin
#tool nuget:?package=TlsClient.Native&version=0.4.6
                    
Install as a Cake Tool

TlsClient.Native

A native (in-process) client for TlsClient.NET.


📦 Installation

dotnet add package TlsClient.Native

Initialize the native library once at process start:

using TlsClient.Native;

NativeTlsClient.Initialize("{PATH_TO_NATIVE_LIBRARY}");
// e.g. Windows: "C:\\tools\\tls-client\\tls-client-windows-64-1.11.0.dll"

🚀 Quick Start

using TlsClient.Native;
using TlsClient.Core.Models.Requests;

NativeTlsClient.Initialize("{PATH_TO_NATIVE_LIBRARY}");

using var client = new NativeTlsClient(); // or pass TlsClientOptions

var res = client.Request(new Request {
    RequestUrl = "https://httpbin.io/get"
});

Console.WriteLine($"{(int)res.Status} {res.Status}");
Console.WriteLine(res.Body);

For advanced configuration, construct with new NativeTlsClient(new TlsClientOptions(...)).


🧱 API Interface

public sealed class NativeTlsClient : BaseTlsClient
{
    // Static bootstrap
    public static void Initialize(string? libraryPath);

    // Constructors
    public NativeTlsClient(TlsClientOptions options);
    public NativeTlsClient();

    // Sync
    public override Response Request(Request request);
    public override GetCookiesFromSessionResponse GetCookies(string url);
    public override GetCookiesFromSessionResponse AddCookies(string url, List<TlsClientCookie> cookies);
    public override DestroyResponse Destroy();
    public override DestroyResponse DestroyAll();

    // Async (wrapping sync)
    public override Task<Response> RequestAsync(Request request, CancellationToken ct = default);
    public override Task<GetCookiesFromSessionResponse> GetCookiesAsync(string url, CancellationToken ct = default);
    public override Task<GetCookiesFromSessionResponse> AddCookiesAsync(string url, List<TlsClientCookie> cookies, CancellationToken ct = default);
    public override Task<DestroyResponse> DestroyAsync(CancellationToken ct = default);
    public override Task<DestroyResponse> DestroyAllAsync(CancellationToken ct = default);
}

🧱 Native Client — Builder Usage

Use the shared TlsClientBuilder to configure common options, then switch to the native transport with WithNative(...) and call Build() to get a NativeTlsClient.

    // 1) Initialize native library once
NativeTlsClient.Initialize("C:\\tools\\tls-client\\tls-client-windows-64-1.11.0.dll");
    // 2) Create client
using var client = new TlsClientBuilder()
    .WithIdentifier(TlsClientIdentifier.Chrome133)
    .WithUserAgent("MyApp/1.0")
    .WithFollowRedirects()
    .WithTimeout(TimeSpan.FromSeconds(15))
    .WithDefaultCookieJar()
    .WithHeader("Accept-Language", "en-US,en;q=0.9")
    .WithProxyUrl("http://127.0.0.1:8086", isRotating: false);
    .withNative() // OPTIONAL
    .build()

    // 3) Make a request
var response = await client.RequestAsync(new Request
{
     RequestUrl = "https://httpbin.io/get"
});

⚠️ Important:

  • Call NativeTlsClient.Initialize(path) once per project before creating clients.
  • You can call .WithNative(path) if you dont want use NativeTlsClient.Initialize(path).
  • Due to C# ↔ Go interop, native mode can be less stable under heavy concurrency. If you run into issues, prefer the API mode.

Under the Hood

  • Initialize(path) loads the native library via TlsClientWrapper.Initialize(...).

  • Request(request):

    • Merges client defaults via PrepareRequest(...).
    • Serializes with RequestHelpers.Prepare(...), calls TlsClientWrapper.Request(...).
    • Deserializes to Response and frees native memory with TlsClientWrapper.FreeMemory(response.Id) when present.
    • Normalizes timeouts: if Status == 0 and Body contains "Client.Timeout exceeded", returns 408 RequestTimeout.
  • Cookie and destroy operations map to corresponding wrapper functions and return strongly-typed results.


⚙️ Requests & Responses (same as Core)

  • Request highlights: RequestUrl (required), RequestMethod, Headers, RequestCookies, RequestBody (string or bytes via RequestHelpers.PrepareBody(...)), IsByteRequest/IsByteResponse, StreamOutputPath, TLS/transport flags (TlsClientIdentifier, WithDefaultCookieJar, WithoutCookieJar, FollowRedirects, Timeout*, etc.).
  • Response: Status (HttpStatusCode), Body (string?, empty if streamed to file), Headers (Dictionary<string, List<string>>), Id (internal handle used to free native buffers).

🧯 Error Handling

  • Native failures set Response.Status = 0 and include the error message in Response.Body.
  • "Client.Timeout exceeded" is normalized to 408 RequestTimeout.
  • Always call Initialize(...) before the first request.
  • Ensure StreamOutputPath targets a writable location.

🔬 Learn More

This page focuses on the API surface and basic usage. For additional scenarios, please refer to the test projects (e.g., BodyTests, CookieTests).


📜 License

MIT — see the root LICENSE file.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
0.4.6 903 3/13/2026
0.4.5 118 3/13/2026
0.4.4 1,280 1/20/2026
0.4.3 444 9/8/2025
0.4.2 188 9/8/2025
0.4.1 183 9/8/2025
0.4.0 180 9/8/2025