Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebRequest.GetResponse taking a long time unless DefaultWebProxy is nulled

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.

like image 923
wal Avatar asked Sep 12 '11 15:09

wal


1 Answers

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.

like image 58
Paul Farry Avatar answered Nov 15 '22 12:11

Paul Farry