c# - 如何处理 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# - 当用户没有将完整的 json 传递给 .NET Web API 时怎么办?
- ruby-on-rails - 如何更改 params 方法以在 rails 控制器中接受 JSON 数组?
- python - 如何知道我是否需要在 findContour 之后反转阈值类型
- java - 用动态创建突破性的新标题
- winapi - 加载图标处理程序外壳扩展时文件图标模糊
- reactjs - react-toastify/dist/ReactToastify.css 模块解析失败。Toastify__toast-container { | 反应 SSR
- highcharts - 即使没有数据,如何显示具有给定开始日期和结束日期的所有日期?
- android - 使用 Tensorflow 构建 Kivy Android 应用
- python - Sci-kit Learn KDE 方差增加一
- c++11 - 我正在尝试查找给定键是否存在于二叉树中。如果密钥存在,我想返回指向节点的指针