c# - WebClient.DownloadString 首次调用时大约需要 15 秒

标签 c# webclient

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/

相关文章:

c# - 将 C++ 函数转换为 C#(字符串问题)

c# - WebClient.DownloadDataAsync 正在卡住我的 UI

c# - 亚音速交易错误

c# - Visual Studio 安装程序问题 : Error 1001. 错误 1001。InstallUtilLib.dll:未知错误

java - htmlunit 在运行项目后总是给出多个 javascript 异常

c# - System.Net.WebClient 在 UploadString 到无效 URL 期间没有抛出错误?

c#-2.0 - WebClient.UploadFile 将上传文件作为流传递

spring-boot - `servletRequest cannot be null` -> SpringBoot - WebClient - 使用 Keycloak 获取请求

c# - 截图工具滞后荧光笔

c# - 在 BackgroundWorker 忙时禁用表单?