8

I'm using Windows 7 Ultimate x64.

I've first had a browse and found this where I got the 'solution' to the issue but would like to know why - I dont want to null the DefaultWebProxy in case there is a legitimate proxy that should be used. (btw I am not behind an http proxy)

Here is a simple unit test that demostrates the issue.

[Test]
    public void TestWebRequest()
    {
        //if I dont include the following line the request takes ~40 seconds.
        WebRequest.DefaultWebProxy = null;

        var httpRequest = WebRequest.Create("http://google.com");                        

        var stopWatch = new Stopwatch();
        stopWatch.Start();
        using (var webResponse = httpRequest.GetResponse())//this is the line taking ages.
        {
            using (var sr = new StreamReader(webResponse.GetResponseStream()))
                Trace.WriteLine(sr.ReadToEnd());
        }
        stopWatch.Stop();
        Trace.WriteLine(string.Format("took {0} sec", stopWatch.Elapsed.TotalSeconds));
    }

Can we please not get bogged down on IDisposable causes.

Community
  • 1
  • 1
wal
  • 17,409
  • 8
  • 74
  • 109
  • I think the reasoning is that HttpWebrequest is trying to do proxy autodetection, and that is why it takes so long. Can you run this program in a loop and get the avg, ignoring the first invocation? How much is the time? – feroze Oct 19 '12 at 06:52
  • sure - why does proxy auto-detection take so long? – wal Oct 19 '12 at 10:06
  • It could depend on your network setup and due to various reasons. It could be that the DNS resolution is slow, or the proxy server is slow to send the autoproxy script, or the autoproxy evaluation from script is taking long. Or the proxy server itself is slow. It is hard to say unless you get a system.net log or a network trace – feroze Oct 20 '12 at 15:58
  • @feroze its been a while since i've had this issue, in fact i've fdisk-ed probably a few times since then. :) I'm not currently having the issue, but I do note that you mention a proxy server - i was never behind a proxy server but that doesnt mean something wasnt trying to auto-detect something. thanks for your help – wal Oct 20 '12 at 23:19
  • 1
    Did you check what `WebRequest.DefaultWebProxy` was before you set it to null? – flindeberg Nov 28 '12 at 08:36
  • I can't confirm or deny that I did. it was a long time ago now and I no longer experience this behavior. I would guess given my strength of language that i did check IE settings for any 'hidden' proxy settings but not `WebRequest.DefaultWebProxy` (which should be the same) – wal Nov 28 '12 at 10:39
  • I'm having the same issue (response taking more or less 1 second) but setting WebRequest.DefaultWebProxy = null doesn't solve my issue. Any other idea? – Cristiano Ghersi Mar 10 '13 at 20:02
  • @CristianoGhersi ah Allora, I suggest you use Fiddler to capture the request, then after capturing right click and select 'Properties' which details the timings of the request, this may help narrow down what is taking so much time, eg DNS lookup, – wal Mar 10 '13 at 23:15
  • You can also set it to null inside instance: ```httpRequest.Proxy = null;``` – aeroson Jul 13 '17 at 14:08

1 Answers1

1

I have seen this and it took some finding to solve.

In my case what happened was someone had entered a " " (space) into the proxy field in the Internet Connection Options and turned on to use Proxy.

It's bizarre, because it only causes the long delay on the 1st start of the Proxy, and if you go back to the internet settings it doesn't show that there is or was a space in there.

Paul Farry
  • 4,730
  • 2
  • 35
  • 61