3

As mentioned before here Why is this WebRequest code slow? and here HttpWebRequest GetResponse delay on 64bit Windows

HttpWebRequest hangs at the first request because of proxy auto-detection. A fix is to set Proxy = null, but this also locks out all users that uses a proxy and thatsway isn't a proper solution.

So, does anyone know how this initial delay can be fixed programatically without locking out all proxy users?

Community
  • 1
  • 1
christophrus
  • 1,170
  • 2
  • 14
  • 27

4 Answers4

1

You could try/catch call first with proxy set to null and with set proxy autodetection in the fail case.

Martin Komischke
  • 1,440
  • 1
  • 13
  • 24
1

I've had similar problem with call Elasticsearch from ASP.NET (C#) when make first request at http://localhost:9200 with GetResponse and GetRequestStream and had 20 sec delay.

The cause of my problem is within IPv6. Solution for my case is comment the definition for the IPv6 address for localhost:

Go to "C:\Windows\system32\drivers\etc\" folder

Make backup of "hosts" file

Edit the file to change line:

::1 localhost

to

#::1 localhost

Also you can change line:

#127.0.0.1 localhost

to

127.0.0.1 localhost

Maybe you can flush DNS cache: start command prompt as Administrator, in the command window type and then hit enter: ipconfig /flushdns

Before that I tried many solution that I found over Internet, but nothing helped for my case, eg.:

  1. request.Proxy = null;
  2. ServicePointManager.UseNagleAlgorithm = false
  3. various changes in web.config ...
Stanislav Prusac
  • 750
  • 10
  • 20
  • In my case resolving request (DNS) at localhost with active IPv6 in hosts file produce delay on first request. Did you try this? This is not only my case, you can find similar problem [http://stackoverflow.com/questions/1416128/my-local-host-goes-so-slow-now-that-i-am-on-windows-7-and-asp-net-mvc](here) , but nobody link problem with GetResponse and GetRequestStream with this solution. – Stanislav Prusac Oct 08 '13 at 10:52
  • But I asked for proper fix, that can be done programatically ... I guess that its not a good idea to let my program modify the users hosts file, is it? – christophrus Oct 08 '13 at 14:24
0

One way is to ask users to turn off proxy auto-detection in Internet explorer options.

alex
  • 12,464
  • 3
  • 46
  • 67
0

the thing that helped me we was to turn off "Automatically detect settings" in Internet explorer LAN Settings. Nothing else worked, including code rewrite to use HttpClient instead of HttpWebRequest.