【发布时间】:2019-09-07 05:23:16
【问题描述】:
如何在每次发出新请求时更改代理? 如果我启动应用程序并多次运行此请求,我可以看到它使用了第一个使用的代理,即使我每次调用此函数时都从代理服务器列表中更改代理参数。我试图处理客户端并将客户端代理设置为空,但它没有帮助。 如果我关闭程序并重新启动它,代理会使用不同的 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;
}
【问题讨论】:
标签: winforms webclient webproxy