A simple HTTP client that routes requests through The Onion Router (Tor) protocol using automatically-managed local Tor proxies.
-
.NET 10.0 or later
-
Tor Expert Bundle installed:
- macOS (using Homebrew):
brew install tor - Ubuntu:
sudo apt install tor - Windows: Currently not supported
Note: Do not start the Tor service. Each Tor HTTP client (class
TorHttpClientinstance) will automatically manage its own Tor proxy. - macOS (using Homebrew):
Create a Tor control password by running tor --hash-password <YOUR_PLAIN_TEXT_PASSWORD>.
Create torrc-defaults file in the same directory as the executable with the following content:
SOCKSPort 9050
ControlPort 9051
HashedControlPassword <YOUR_HASHED_PASSWORD>
Create onionhttpclient.secrets.json in the same directory as the executable with the following content:
{
"Tor": {
"ControlPassword": "<YOUR_PLAIN_TEXT_PASSWORD>"
}
}Manages an internal HTTP client and Tor service.
using Kokoabim.OnionHttpClient;
hostBuilder.AddOnionHttpClient();
// --- OR ---
serviceCollection.AddOnionHttpClient();
...
var httpClientSettings = new HttpClientInstanceSettings()
{
...
};
var torSettings = new TorInstanceSettings();
using var torHttpClient = services.GetRequiredService<ITorHttpClient>();
await torHttpClient.InitializeAsync(httpClientSettings, torSettings);
var response = await torHttpClient.GetResponseAsync(...);
// --- OR ---
var response = await torHttpClient.SendAsync(...);
...
await torHttpClient.DisconnectAsync();Manages multiple internal HTTP clients and Tor services and balances requests between them.
using Kokoabim.OnionHttpClient;
hostBuilder.AddOnionHttpClient();
// --- OR ---
serviceCollection.AddOnionHttpClient();
...
var multiTorHttpClientSettings = new MultiTorHttpClientSettings
{
BalanceStrategy = MultiTorHttpClientBalanceStrategy.RoundRobin,
ClientCount = 2,
...
};
var httpClientCommonSettings = new HttpClientCommonSettings()
{
...
};
using var multiTorHttpClient = services.GetRequiredService<IMultiTorHttpClient>();
await multiTorHttpClient.InitializeAsync(multiTorHttpClientSettings, httpClientCommonSettings);
var response = await multiTorHttpClient.GetResponseAsync(...);
// --- OR ---
var response = await multiTorHttpClient.SendAsync(...);
...
await multiTorHttpClient.DisconnectAsync();