Winforms 随每个新请求更改webclient代理
如何在每次提出新请求时更改代理? 如果我启动应用程序并多次运行此请求,我可以看到它使用了使用的第一个代理,即使我每次调用此函数时都从代理服务器列表中更改代理的参数。我试图处理客户端,并将客户端代理设置为null,但没有帮助。 如果关闭程序并重新启动,代理将使用不同的IP地址Winforms 随每个新请求更改webclient代理,winforms,webclient,webproxy,Winforms,Webclient,Webproxy,如何在每次提出新请求时更改代理? 如果我启动应用程序并多次运行此请求,我可以看到它使用了使用的第一个代理,即使我每次调用此函数时都从代理服务器列表中更改代理的参数。我试图处理客户端,并将客户端代理设置为null,但没有帮助。 如果关闭程序并重新启动,代理将使用不同的IP地址 string GetRequest() { WebClient client = new WebClient(); WebProxy wp = new WebProxy(randomProxyAddress + "
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;
}
我发现我必须在WebClient中设置request.KeepAlive=false