Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 随每个新请求更改webclient代理_Winforms_Webclient_Webproxy - Fatal编程技术网

Winforms 随每个新请求更改webclient代理

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

如何在每次提出新请求时更改代理? 如果我启动应用程序并多次运行此请求,我可以看到它使用了使用的第一个代理,即使我每次调用此函数时都从代理服务器列表中更改代理的参数。我试图处理客户端,并将客户端代理设置为null,但没有帮助。 如果关闭程序并重新启动,代理将使用不同的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;
}

我发现我必须在WebClient中设置request.KeepAlive=false