Reputation: 101
In my code (C#) I'm using a WebRequest:
var request = WebRequest.Create(url);
For some reason this line takes about 2-3 seconds to run. I've looked for a solution, but couldn't find any for the creation of the request. I've tried different urls (http and https, google, etc.) but nothing seems to help. Did anyone else experience such a behavior? Can anyone explain what exactly is going on during the creation of the request? Any alternatives?
BTW - I'm on a 64bit Win 7 (Bootcamp)
Edit - measured 3.126 seconds with Stopwatch for the following code (wireless):
var request = WebRequest.Create("http://www.google.com");
On the same network, only wired, it took 0.01 seconds.
Thanks everyone!
Upvotes: 0
Views: 140
Reputation: 156708
Some people have found that proxy detection can take a ridiculously long time. If you know there won't be a proxy, try setting the WebRequest's proxy property to null.
var request = WebRequest.Create("http://www.google.com");
request.Proxy = null;
I don't have any other ideas, but here are some things you might try to narrow down the problem.
Enable logging by putting the following code in your config file:
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<switches>
<add name="System.Net" value="Verbose"/>
</switches>
</system.diagnostics>
</configuration>
Check out the source code for WebRequest.Create
in ILSpy or a similar tool, and try doing the same things it does directly. For example, you can try creating a new HttpWebRequest(...)
rather than calling WebRequest.Create
and see if you get the same behavior.
Upvotes: 1