C# and .NET with AeonProxy proxies
Give HttpClient a WebProxy with your login, and every request goes out through residential or mobile IPs, over HTTP or SOCKS5.
- Protocols
- HTTP proxy for HTTP and HTTPS sites; SOCKS5 in .NET 6 and newer
- Authentication
NetworkCredentialon theWebProxy- Rotation
- A new IP per connection (HttpClient pools its connections); a
-sid-key keeps one IP for up to 60 minutes - Works with
- Residential and mobile proxies
Before you start
- .NET 6 or newer (older versions have no SOCKS5 in
HttpClient). Create a project withdotnet new consoleand put the code inProgram.cs. - Your proxy login and password from the Residential or Mobile page of the dashboard, and traffic on that product; a login without traffic gets 402.
- Host
gate.aeonproxy.com- Port (HTTP / HTTPS)
7000- Port (SOCKS5)
7001- Login
- your proxy login, with targeting keys if you need them:
LOGIN-cc-us-sid-abc123 - Password
- your proxy password
Copy the login and password from the Residential or Mobile page of the dashboard; the generator there also writes ready lines. Key syntax: targeting and sessions.
HttpClient with a WebProxy
Point a WebProxy at port 7000 with an http:// address and give it the login and password as a NetworkCredential. HTTPS sites go through a CONNECT tunnel, so the address stays http://; an https:// proxy address makes .NET start TLS with the proxy, which fails.
using System.Net;
var proxy = new WebProxy("http://gate.aeonproxy.com:7000")
{
Credentials = new NetworkCredential("LOGIN-cc-us", "PASSWORD"),
};
var handler = new HttpClientHandler { Proxy = proxy, UseProxy = true };
using var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };
Console.WriteLine(await client.GetStringAsync("https://api.ipify.org"));Create the client once and reuse it. It keeps a pool of connections, and each new one costs an extra round trip: .NET sends the proxy login only after the gateway answers 407.
Rotating or sticky
A rotating login gets a new IP for every connection, and pooled connections are reused, so requests in a row usually share one. PooledConnectionLifetime = TimeSpan.Zero on a SocketsHttpHandler opens a new connection for every request. With a -sid- key, every connection keeps the same IP until the -ttl- runs out (1 to 60 minutes).
Over the HTTP proxy, every new connection starts without the login and sends it after the gateway's 407, so a new connection per request costs an extra round trip each time; the gateway does not count those first tries as failed logins. A Proxy-Authorization request header does not save the round trip, because .NET does not send it on the CONNECT. SOCKS5 sends the login in its handshake, so for a new connection per request it is the quicker choice.
using System.Net;
// SOCKS5 sends the login in its handshake, so every new connection is accepted at once
static HttpClient NewClient(string login, bool newConnectionEachTime) => new(new SocketsHttpHandler
{
Proxy = new WebProxy("socks5://gate.aeonproxy.com:7001") { Credentials = new NetworkCredential(login, "PASSWORD") },
PooledConnectionLifetime = newConnectionEachTime ? TimeSpan.Zero : TimeSpan.FromMinutes(10),
ConnectTimeout = TimeSpan.FromSeconds(30),
});
// rotating: a new connection for every request, so a new IP each time
using var rotating = NewClient("LOGIN-cc-us", newConnectionEachTime: true);
Console.WriteLine(await rotating.GetStringAsync("https://api.ipify.org"));
Console.WriteLine(await rotating.GetStringAsync("https://api.ipify.org"));
// sticky: one key keeps one IP for up to 30 minutes
var sid = Guid.NewGuid().ToString("N")[..8];
using var sticky = NewClient($"LOGIN-cc-us-sid-{sid}-ttl-30", newConnectionEachTime: false);
Console.WriteLine(await sticky.GetStringAsync("https://api.ipify.org"));
Console.WriteLine(await sticky.GetStringAsync("https://api.ipify.org"));SOCKS5
Pass a socks5:// address to WebProxy (the host-and-port constructor builds HTTP proxies only). The login comes from the NetworkCredential, and .NET sends the site's name to the proxy, so DNS is resolved at the gateway.
using System.Net;
var proxy = new WebProxy("socks5://gate.aeonproxy.com:7001")
{
Credentials = new NetworkCredential("LOGIN-cc-de", "PASSWORD"),
};
using var client = new HttpClient(new SocketsHttpHandler { Proxy = proxy });
Console.WriteLine(await client.GetStringAsync("https://api.ipify.org"));If it does not work
| What you see | What to check |
|---|---|
The proxy tunnel request to proxy '...' failed with status code '407' | The login, the password, or a key in the login that is not in the lists (a misspelled city, for example). |
The same with '402' | No traffic left on the product, or the sub-user reached its limit. |
The same with '502' | The exit failed. Retry: a new connection of a rotating login gets a new IP. |
The same with '429' | 30 failed logins in a minute from your address: a wrong login, password or key, repeated by many connections. Fix the login and wait a minute. |
An error occurred while establishing a connection to the proxy tunnel, inner exception Failed to authenticate with the SOCKS server | The gateway refused the SOCKS5 login. SOCKS5 has one failure code for every cause: check the login, the password, the keys and the traffic left. |
The SSL connection could not be established | An https:// proxy address. Use http:// for port 7000. |
Questions
No. Create one per login, or per sticky key, and reuse it; bought traffic has no thread or connection limit on the gateway. Control connection reuse with PooledConnectionLifetime instead of creating and disposing clients.
Yes. When no proxy is set on the handler, .NET reads HTTPS_PROXY, HTTP_PROXY and ALL_PROXY, login included: http://LOGIN:[email protected]:7000. It still waits for the 407 before it sends the login.