WebClient.DownloadString takes about 15 seconds when the first call

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); 

The stopwatch says that the DownloadString method takes 13-15 seconds on the first call, but repeated calls require a reasonable amount of time. How does this happen and how to fix it?

+5
source share
2 answers

There may be several things that may cause a delay on the first call, for example, defining proxy server settings. Try setting the proxy server to null:

 client.Proxy = null; 
+9
source

Your computer is configured to automatically detect a proxy server.

You can disable it here:

Screen shot

Alternatively, you can manually override the proxy that WebClient will use; null means no proxy:

 client.Proxy = null; 

However, in this case, you should prompt the user to configure the proxy server in their application, as some users must use the proxy server when accessing the Internet.

+9
source

Source: https://habr.com/ru/post/1412203/


All Articles