Note that there are some explanatory texts on larger screens.

plurals
  1. POSystem.Net.WebClient unreasonably slow
    text
    copied!<p>When using the <a href="http://msdn.microsoft.com/en-us/library/system.net.webclient(v=VS.100).aspx" rel="nofollow noreferrer">System.Net.WebClient.DownloadData()</a> method I'm getting an unreasonably slow response time.</p> <p>When fetching an url using the WebClient class in .NET it takes around 10 sec before I get a response, while the same page is fetched by my browser in under 1 sec. And this is with data that's 0.5kB or smaller in size.</p> <p>The request involves POST/GET parameters and a user agent header if perhaps that could cause problems.</p> <p>I haven't (yet) tried if other ways to download data in .NET gives me the same problems, but I'm suspecting I might get similar results. (I've always had a feeling web requests in .NET are unusually slow...)</p> <p>What could be the cause of this?</p> <p><strong>Edit:</strong> <br> I tried doing the exact thing using <code>System.Net.HttpWebRequest</code> instead, using the following method, and all requests finish in under 1 sec.</p> <pre><code>public static string DownloadText(string url) var request = (HttpWebRequest)WebRequest.Create(url); var response = (HttpWebResponse)request.GetResponse(); using (var reader = new StreamReader(response.GetResponseStream())) { return reader.ReadToEnd(); } } </code></pre> <p><br>While this (old) method using <code>System.Net.WebClient</code> takes 15-30s for each request to finish:</p> <pre><code>public static string DownloadText(string url) { var client = new WebClient(); byte[] data = client.DownloadData(url); return client.Encoding.GetString(data); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload