RuriLib.Http
2.0.0
dotnet add package RuriLib.Http --version 2.0.0
NuGet\Install-Package RuriLib.Http -Version 2.0.0
<PackageReference Include="RuriLib.Http" Version="2.0.0" />
<PackageVersion Include="RuriLib.Http" Version="2.0.0" />
<PackageReference Include="RuriLib.Http" />
paket add RuriLib.Http --version 2.0.0
#r "nuget: RuriLib.Http, 2.0.0"
#:package RuriLib.Http@2.0.0
#addin nuget:?package=RuriLib.Http&version=2.0.0
#tool nuget:?package=RuriLib.Http&version=2.0.0
RuriLib.Http
This is a library that provides a custom HTTP client, an HttpMessageHandler to be used with the default HttpClient of System.Net, and a curl-impersonate-backed HTTP client for browser-like TLS and HTTP fingerprints. It sits on top of RuriLib.Proxies which provides a layer 4 proxied connection.
Features:
- Custom proxied HTTP client
HttpMessageHandlerintegration withSystem.Net.Http.HttpClient- curl-impersonate integration with packaged native runtime assets
- HTTP, SOCKS and proxiless connections through
RuriLib.Proxies - gzip, deflate, brotli and zstd response decoding
- Cookie parsing and cookie container support
Requirements
Version 2.x targets .NET 10.
Installation
NuGet: dotnet add package RuriLib.Http
Example (Custom Client)
using RuriLib.Http;
using RuriLib.Http.Models;
using RuriLib.Proxies;
using RuriLib.Proxies.Clients;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace HttpDemo
{
class Program
{
static void Main(string[] args)
{
_ = MainAsync(args);
Console.ReadLine();
}
static async Task MainAsync(string[] args)
{
// Set up the proxy client (see RuriLib.Proxies documentation, here we use
// a NoProxyClient for simplicity)
var settings = new ProxySettings();
var proxyClient = new NoProxyClient(settings);
// Create the custom proxied client
using var client = new RLHttpClient(proxyClient);
// Create the request
using var request = new HttpRequest
{
Uri = new Uri("https://httpbin.org/anything"),
Method = HttpMethod.Post,
Headers = new Dictionary<string, string>
{
{ "Authorization", "Bearer ey..." }
},
Cookies = new Dictionary<string, string>
{
{ "PHPSESSID", "12345" }
},
// Content a.k.a. the "post data"
Content = new StringContent("My content", Encoding.UTF8, "text/plain")
};
// Send the request and get the response (this can fail so make sure to wrap it in a try/catch block)
using var response = await client.SendAsync(request);
// Read and print the content of the response
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
Example (HttpClient)
This example is equivalent to the one above, but it uses the default HttpClient so you can take advantage of the API you are already familiar with.
using RuriLib.Http;
using RuriLib.Proxies;
using RuriLib.Proxies.Clients;
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace HttpDemo
{
class Program
{
static void Main(string[] args)
{
_ = MainAsync(args);
Console.ReadLine();
}
static async Task MainAsync(string[] args)
{
// Set up the proxy client (see RuriLib.Proxies documentation, here we use
// a NoProxyClient for simplicity)
var settings = new ProxySettings();
var proxyClient = new NoProxyClient(settings);
// Create the handler that will be passed to HttpClient
var handler = new ProxyClientHandler(proxyClient)
{
// This adds cookie support
CookieContainer = new CookieContainer()
};
// Create the proxied HttpClient and the cookie container
using var client = new HttpClient(handler);
// Create the request
using var request = new HttpRequestMessage
{
RequestUri = new Uri("https://httpbin.org/anything"),
Method = HttpMethod.Post,
// Content a.k.a. the "post data"
Content = new StringContent("My content", Encoding.UTF8, "text/plain")
};
request.Headers.TryAddWithoutValidation("Authorization", "Bearer ey...");
handler.CookieContainer.Add(request.RequestUri, new Cookie("PHPSESSID", "12345"));
// Send the request and get the response (this can fail so make sure to wrap it in a try/catch block)
using var response = await client.SendAsync(request);
// Read and print the content of the response
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
Example (curl-impersonate)
This example uses curl-impersonate for browser-like TLS and HTTP fingerprints.
using RuriLib.Http.Curl;
using RuriLib.Http.Models;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace HttpDemo
{
class Program
{
static void Main(string[] args)
{
_ = MainAsync(args);
Console.ReadLine();
}
static async Task MainAsync(string[] args)
{
var options = new CurlImpersonateHandlerOptions
{
BrowserProfile = CurlImpersonateBrowserProfile.Chrome142
};
using var client = new CurlImpersonateHttpClient(options);
using var request = new HttpRequest
{
Uri = new Uri("https://example.com"),
Method = HttpMethod.Get
};
using var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
Changelog
See CHANGELOG.md for release notes.
Credits
Some portions of the code were the work of Ruslan Khuduev and Artem Dontsov, to which I am grateful, all rights are reserved to them. Their work is under the MIT license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- RuriLib.Proxies (>= 2.0.0)
- ZstdSharp.Port (>= 0.8.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.