9

I see the post from https://stackoverflow.com/questions/6262547/webclient-timeout-error , it says the default timeout is 100 seconds. But I see the comment from How to change the timeout on a .NET WebClient object says

The default timeout is 100 seconds. Although it seems to run for 30 seconds. – Carter Dec 13 '12 at 16:39

In my program the timeout always about 20 seconds, does anybody know the reason?

Community
  • 1
  • 1
MichaelMao
  • 1,739
  • 2
  • 18
  • 44
  • HttpWebRequest Timeout is 100 seconds, Session timeout is 20 minutes. – sansknwoledge Dec 04 '15 at 07:50
  • 2
    Sorry @sansknwoledge, this not help. – MichaelMao Dec 04 '15 at 07:52
  • 1
    yep , that was pumped up comment, have you checked out msdn https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout(v=vs.110).aspx , especially the last para, – sansknwoledge Dec 04 '15 at 07:57
  • Yes, I have checked that, but I think it's the different issue. My question is if default timeout is 100 seconds. Why my program will timeout during 20 seconds and the comment say 30 seconds. – MichaelMao Dec 04 '15 at 08:04
  • 1
    With HttpClient I'm seeing similar 20 second timeout. Changing the TimeOut setting does not raise it any higher (but does lower it). .NET Core project issue tracker has some discussion about an issue which might be related: https://github.com/dotnet/corefx/issues/2857 – Juha Palomäki Jan 17 '17 at 21:37

1 Answers1

11

I put together a minimal case to test the WebClient class's default timeout.

I published a simple website to my local PC which, upon receiving a request, waits 300 seconds (long enough to make WebClient time out), and then returns a response.

I wrote a simple program which uses a WebClient to make a request to that site, and report what happens:

void Main()
{
    Console.WriteLine("Starting request at " + DateTime.Now);
    WebClient client = new WebClient();
    try
    {
        string response = client.DownloadString("http://slowsite.local/");
        Console.WriteLine("Response returned at " + DateTime.Now);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.GetType() + " " + ex.Message + " at " + DateTime.Now);
    }
}

The WebClient did time out after 100 seconds. The program produced this output:

Starting request at 8/1/2017 9:31:11 AM
System.Net.WebException The request was aborted: The operation has timed out. at 8/1/2017 9:32:51 AM

The client test program targeted .NET Framework 4.6.

Jon Schneider
  • 23,615
  • 19
  • 137
  • 163
  • Hi Jon, good test but someone got same problem with me so I can't choose you answer as the real answer – MichaelMao Aug 02 '17 at 04:42
  • 3
    Can you post minimal repro code, so we can see what your program is doing differently than my code? It might also be helpful if you could post the details of the exception you are getting, and the .NET version your program uses. – Jon Schneider Aug 02 '17 at 04:54
  • Give me some days LOL – MichaelMao Aug 02 '17 at 05:11