无论如何要重置webclient? [英] Is there anyway to reset webclient?

查看:62
本文介绍了无论如何要重置webclient?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 webclient 解析一些非常敏感的网页时遇到问题.不知何故,webclient 无法完成某些任务,我什至不知道为什么,没有例外,没有错误,只是简单的无法工作(这不是网站的问题)

Im experiencing problem with webclient to parse some very sensitive webpage. Somehow, webclient failed to do some task, and i dont even know why, no exception, no error, just simple not working (this is not the problem from the site)

我循环运行 webclient,但是,只有第一个请求成功,接下来的所有请求都失败了.当我重新启动应用程序时,出现相同的结果,第一个请求总是成功,而所有其他请求都失败.

I run webclient in a loop, however, only the first request was success, all the next requests are failed. When i restart the application, the same result appear, the first request always succeed, while all other request are failed.

我确定所有的 webclient 都被正确处理,但我不知道是什么问题,即使在处理后 webclient 还会保存信息吗?

Im sure all webclient are disposed properly, but i don't know what is the problem, is webclient saving information even after dispose?

请指导我如何清除所有内容、重置所有内容并启动全新的网络客户端.

Please guide me how to clear everything, reset everything and start brand new webclient.

for (int i = 1; i <= Count; i++)
{
    using (WebClient wc = new WebClient())
    {
        wc.Headers["Accept-Encoding"] = "gzip";
        wc.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
        byte[] arr = wc.DownloadData(url);

        if (arr.Length > 0)
            Console.WriteLine(i.ToString() + ": SUCCESS");
        else
            Console.WriteLine(i.ToString() + ": FAILED");
    }
}

推荐答案

WebClient 不会在实例之间共享任何信息.
您可能遇到了不同的问题.

WebClient will not share any information between instances.
You probably have a different problem.

例如,站点可能会忽略发生过于频繁的请求.

For example, the site might ignore requests that happen too frequently.

您应该运行 Fiddler 并检查到底发生了什么.

You should run Fiddler and check exactly what is happening.

此外,尝试在循环中添加 Thread.Sleep(5000) 并查看是否有任何变化.(在提琴手中)

Also, try adding Thread.Sleep(5000) in the loop and see whether anything changes. (In Fiddler)

这篇关于无论如何要重置webclient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆