如何在每次提出新请求时更改代理?
如果关闭程序并重新启动,代理将使用不同的IP地址。
string GetRequest()
{
WebClient client = new WebClient();
WebProxy wp = new WebProxy(randomProxyAddress + ":" + portNum);
wp.UseDefaultCredentials = false;
wp.Credentials = new NetworkCredential(username, password);
client.Proxy = wp;
string str = client.DownloadString("http://www.example.com");
client.Proxy = null;
client.Dispose();
return str;
}