Http2Client provides customizable HTTP/2 clients with TLS fingerprinting capabilities. Based on bogdanfinn/tls-client, it allows you to mimic specific browser fingerprints and control detailed aspects of TLS behavior in your .NET applications.
dotnet add package Http2Client
Http2Client requires the native TLS library from the original bogdanfinn/tls-client repository. Download the appropriate library for your platform from the latest release:
Operating System | Architecture | Library File | Download Link |
---|---|---|---|
Windows | x64 (64-bit) | tls-client-windows-64-1.11.0.dll |
Download |
Windows | x86 (32-bit) | tls-client-windows-32-1.11.0.dll |
Download |
Linux | AMD64 (64-bit) | tls-client-linux-ubuntu-amd64-1.11.0.so |
Download |
Linux | ARM64 | tls-client-linux-arm64-1.11.0.so |
Download |
Linux | ARMv7 | tls-client-linux-armv7-1.11.0.so |
Download |
macOS | AMD64 (Intel) | tls-client-darwin-amd64-1.11.0.dylib |
Download |
macOS | ARM64 (Apple Silicon) | tls-client-darwin-arm64-1.11.0.dylib |
Download |
đź“‹ Full Library List: For additional architectures and XGO builds (including Linux 386, ARM variants, PowerPC, RISC-V, s390x), see the complete list at v1.11.0 release page.
Installation Instructions:
- Download the appropriate library file for your platform from the table above
- Place the native library in your application's output directory, or specify a custom path
- Initialize the library once at application startup using
Http2Client.Initialize()
Example for Windows:
// Initialize once at application startup
Http2Client.Initialize("tls-client-windows-64-1.11.0.dll");
// Create clients as needed
using var client = new HttpClientBuilder()
.Build();
Important: The native library is required for Http2Client to function properly. Always use the latest version from the original repository releases.
Note: When building your application, ensure the correct native library is included in your published application. For cross-platform deployment, you may need to include multiple libraries and select the appropriate one at runtime based on the target platform.
Below is a full example that shows how to configure an Http2Client
, build a request, and send it.
using Http2Client;
using Http2Client.Builders;
using Http2Client.Core.Enums;
using Http2Client.Core.Request;
// Initialize native library once at application startup
Http2Client.Initialize("tls-client-windows-64-1.11.0.dll");
// Create an Http2Client instance using the builder
using var client = new HttpClientBuilder()
.WithBrowserType(BrowserType.Chrome133)
.WithUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
.WithTimeout(TimeSpan.FromSeconds(30))
.WithCookies()
.Build();
// Create a request
var request = new HttpRequest
{
RequestUrl = "https://httpbin.org/post",
RequestMethod = "POST",
RequestBody = "{\"message\": \"Hello from Http2Client\"}",
Headers = { ["Content-Type"] = "application/json" }
};
// Send the request
var response = client.Send(request);
Console.WriteLine($"Status: {response.Status}");
Console.WriteLine($"Body: {response.Body}");
Http2Client provides methods for managing cookies and sessions:
// Get cookies for a specific URL
var cookies = client.GetCookies("https://example.com");
// Add cookies to session
var newCookies = new List<ClientCookie>
{
new ClientCookie("session", "abc123")
};
client.AddCookies("https://example.com", newCookies);
// Clean up session when done
client.DestroySession();
The HttpClientBuilder
class provides a fluent interface to create and configure an Http2Client
instance with custom options such as browser fingerprints, headers, proxy settings, timeouts, and other TLS behaviors.
using var client = new HttpClientBuilder()
.WithBrowserType(BrowserType.Chrome133)
.WithUserAgent("Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36")
.WithTimeout(TimeSpan.FromSeconds(30))
.WithCookies()
.Build();
Method | Description |
---|---|
WithBrowserType(BrowserType) |
Sets the browser fingerprint to mimic. |
WithUserAgent(string) |
Sets the User-Agent header. |
WithTimeout(TimeSpan) |
Sets the request timeout. |
WithProxy(string, bool) |
Configures proxy URL and rotation setting. |
WithInsecureSkipVerify(bool) |
Skips SSL certificate verification. |
WithRandomTlsExtensions(bool) |
Randomizes TLS extension order. |
WithCookies(bool) |
Enables automatic cookie handling. |
WithoutCookieJar(bool) |
Disables all cookie handling. |
WithDebug(bool) |
Enables debug logging. |
WithDisableIPv4(bool) |
Disables IPv4 connections. |
WithDisableIPv6(bool) |
Disables IPv6 connections. |
WithFollowRedirects(bool) |
Enables automatic redirect following. |
WithForceHttp1(bool) |
Forces HTTP/1.1 instead of HTTP/2. |
WithHeader(string, string) |
Sets a default header. |
WithHeaders(Dictionary<string, string>) |
Sets multiple default headers. |
WithHeaderOrder(params string[]) |
Sets the order of HTTP headers. |
WithSessionId(Guid) |
Sets the session ID for this client. |
WithCustomHttp2Client(CustomHttp2Client) |
Uses custom TLS fingerprint. |
WithCatchPanics(bool) |
Catches native library panics. |
// Initialize library once at startup
Http2Client.Initialize("tls-client-windows-64-1.11.0.dll");
using var client = new HttpClientBuilder()
.WithBrowserType(BrowserType.Firefox132)
.WithUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
.WithProxy("http://127.0.0.1:8888", isRotating: true)
.WithTimeout(TimeSpan.FromSeconds(30))
.WithDebug(true)
.WithFollowRedirects(true)
.WithInsecureSkipVerify(false)
.WithDisableIPv6(true)
.WithHeader("X-Custom-Header", "MyValue")
.WithCookies()
.Build();
The HttpRequest
class represents an HTTP request with all necessary configuration. You can create it directly or use the builder pattern.
For more complex request configuration, use the fluent HttpRequestBuilder
:
var request = new HttpRequestBuilder()
.WithUrl("https://api.example.com/data")
.WithMethod(HttpMethod.Post)
.WithJsonBody(new { name = "John", age = 30 })
.WithBrowserType(BrowserType.Chrome133)
.WithTimeout(TimeSpan.FromSeconds(30))
.WithProxy("http://proxy.example.com:8080")
.Build();
var response = client.Send(request);
var request = new HttpRequest
{
RequestUrl = "https://example.com/api/data",
RequestMethod = "POST",
RequestBody = "{\"id\": 123, \"name\": \"example\"}",
Headers =
{
["Content-Type"] = "application/json",
["Authorization"] = "Bearer token"
},
BrowserType = BrowserType.Chrome133,
TimeoutMilliseconds = 30000
};
Property | Description |
---|---|
RequestUrl |
The target URL (required). |
RequestMethod |
HTTP method (GET, POST, etc.). |
RequestBody |
Request body content. |
Headers |
Dictionary of HTTP headers. |
BrowserType |
Browser fingerprint to use. |
TimeoutMilliseconds |
Request timeout in milliseconds. |
TimeoutSeconds |
Request timeout in seconds. |
ProxyUrl |
Proxy server URL. |
InsecureSkipVerify |
Skip SSL certificate verification. |
FollowRedirects |
Follow HTTP redirects automatically. |
RequestCookies |
List of cookies for this request. |
WithDebug |
Enable debug logging for this request. |
- HTTP/2 and HTTP/1.1 support
- TLS fingerprinting with multiple browser profiles
- Cross-platform (Windows, Linux, macOS)
- Proxy support (HTTP, HTTPS, SOCKS5)
- Cookie management
- Custom headers and SSL configuration
using var client = new HttpClientBuilder()
.WithBrowserType(BrowserType.Chrome133)
.Build();
var request = new HttpRequest
{
RequestUrl = "https://httpbin.org/headers",
RequestMethod = "GET",
Headers =
{
["X-Custom-Header"] = "custom-value",
["User-Agent"] = "MyApp/1.0"
}
};
var response = client.Send(request);
Console.WriteLine(response.Body);
var request = new HttpRequest
{
RequestUrl = "https://httpbin.org/post",
RequestMethod = "POST",
RequestBody = "{\"name\": \"John\", \"age\": 30}",
Headers = { ["Content-Type"] = "application/json" }
};
var response = client.Send(request);
using var client = new HttpClientBuilder()
.WithBrowserType(BrowserType.Chrome133)
.WithProxy("http://proxy.example.com:8080")
.Build();
Http2Client supports multiple .NET versions:
- .NET Standard 2.0 - For maximum compatibility
- .NET 5.0 - Legacy LTS support
- .NET 6.0 - LTS support
- .NET 8.0 - Current LTS
- .NET 9.0 - Latest version
Licensed under MIT. Report an Issue