none
Operation time out error RRS feed

  • Question

  •   

    HI,

    I am using the below code for calling  api (https) , some times i am getting Operation time out error  . Any thoughts on this ?

    I tried to increase the time out also but no luck. 

    ServicePointManager.Expect100Continue = true;
      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;


       var webrequest = (HttpWebRequest)System.Net.WebRequest.Create(url);         
       webrequest.Credentials = new NetworkCredential("username", "password");
       webrequest.Timeout = 50000;
       using (var response = webrequest.GetResponse())
       using (var reader = new StreamReader(response.GetResponseStream()))
                {

                }


    Tuesday, June 30, 2020 5:58 AM

All replies

  • It can happen. If the remote server takes too long to respond for whatever reason (slow, busy, etc) then you'll get a timeout error. There is nothing you can do to stop this. Most people implement a retry policy using Polly or something along those lines as timeouts are going to happen.

    I would recommend you don't muck with the timeout property though. You are setting it for 50 seconds. The default for HTTP is 100 seconds which is closer to the actual HTTP timeout interval.

    I should also point out that WebRequest for HTTP has been deprecated for quite some time. Consider using HttpClient which is harder to use but far more flexible. It has the same timeout issues but most libraries can work with HttpClient, not HttpWebRequest.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, June 30, 2020 1:16 PM
    Moderator