首页 > 解决方案 > 如何处理 WebClient/代理 C#

问题描述

处理我的 Webclient 请求的最佳实践是什么?现在,如您所见,我只是让它在错误日志中显示“失败”代理和错误类型。

我环顾四周,但未能找到有关正确处理方式的大量信息。

using (WebClient client = new WebClient())
           {            
               foreach (var line in fileInfo)
           {               
                   foreach (var lines in proxies)
                   {                     
                       WebProxy proxy = new WebProxy(lines);
                       try
                       {
                           client.Proxy = proxy;
                           string downloadString = await client.DownloadStringTaskAsync("url");

                       }

                       catch (WebException ex)
                       {
                           if (ex.Status == WebExceptionStatus.RequestProhibitedByCachePolicy)
                           { 

                               errorTb.Text += lines + " ERROR request prohib";
                               client.Dispose();
                               continue;
                           }

为了让我的程序有效运行,我需要为每个代理设置某种计时器?

非常感谢您的宝贵时间,非常感谢。

标签: c#error-handlingwebclient

解决方案


推荐阅读