WebProxy

using System;
using System.Net;
using System.Net.WebProxy;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// 代理服务器的地址和端口
string proxyAddress = "http://your_proxy_server:port";
// 创建一个新的WebProxy实例
WebProxy proxy = new WebProxy(proxyAddress, false);
// 设置代理服务器的用户名和密码(如果需要)
proxy.Credentials = new NetworkCredential("username", "password");
// 创建一个WebClient实例,并使用代理服务器
using (WebClient client = new WebClient())
{
// 设置WebClient使用代理服务器
client.Proxy = proxy;
try
{
// 发送一个GET请求到目标URL
string result = await client.GetStringAsync("http://example.com");
// 输出结果
Console.WriteLine(result);
}
catch (WebException ex)
{
// 处理异常
Console.WriteLine("Error: " + ex.Message);
}
}
}
}
WebProxyWebClient
your_proxy_serverport