-
Notifications
You must be signed in to change notification settings - Fork 1
/
csharp-example.cs
47 lines (42 loc) · 1.47 KB
/
csharp-example.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
class CSharpExample
{
static async Task Main(string[] args)
{
string proxyUsername = Environment.GetEnvironmentVariable("proxy_username");
string proxyPassword = Environment.GetEnvironmentVariable("proxy_password");
if (string.IsNullOrEmpty(proxyUsername) || string.IsNullOrEmpty(proxyPassword))
{
Console.WriteLine("Error: Proxy credentials not set. Please set proxy_username and proxy_password.");
Console.WriteLine("Example:");
Console.WriteLine("export proxy_username=your_username");
Console.WriteLine("export proxy_password=your_password");
Environment.Exit(1);
}
try
{
var proxy = new WebProxy
{
Address = new Uri($"http://rp.evomi.com:1000"),
Credentials = new NetworkCredential($"customer-{proxyUsername}", proxyPassword)
};
var handler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true,
};
using (var client = new HttpClient(handler))
{
var response = await client.GetStringAsync("https://ip.evomi.com/");
Console.WriteLine(response);
}
}
catch (Exception e)
{
Console.WriteLine($"An error occurred: {e.Message}");
}
}
}