string url = "http://google.com/index.html";
WebClient client = new WebClient();
Stopwatch sw = new Stopwatch();
sw.Start();
string text = client.DownloadString(url);
sw.Stop();
Console.WriteLine(sw.Elapsed);
秒表显示 DownloadString
方法在首次调用时需要 13-15 秒,但重复调用会花费合理的时间。这是怎么发生的,我该如何解决?
最佳答案
可能有几件事会导致第一次调用延迟,例如检测代理设置。尝试将代理设置为空:
client.Proxy = null;
关于c# - WebClient.DownloadString 首次调用时大约需要 15 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10568321/