Web request timeout

How long does it take to wait for a web request to return? I know this may be a bit loaded as a question, but all I'm trying to do is check if the webpage is accessible.

Maybe there is a better way?

try 
{ 
    // Create the web request 
    HttpWebRequest request = WebRequest.Create(this.getUri()) as HttpWebRequest;

    request.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // 2 minutes for timeout
    request.Timeout = 120 * 1000;

    if (request != null)
    {
        // Get response 
        response = request.GetResponse() as HttpWebResponse;

        connectedToUrl = processResponseCode(response);
    }
    else
    {
        logger.Fatal(getFatalMessage());

        string error = string.Empty;
    }
} 
catch (WebException we) 
{ 
...
} 
catch (Exception e) 
{ 
...
} 
+5
source share
8 answers

You need to think about how long a web service consumer will take, for example. if you connect to the database web server and run a long request, you need to make the web service timeout longer than the request will be executed. Otherwise, the web service will (erroneously) disconnect.

I also use something like (consumer time) + 10 seconds.

+5
source

10 , , . /, , .

+2

, , . , .

+2

, -. , :

period += (numTimeouts/numRequests > .01 ? someConstant: 0);

, , - 1% (). , :)

+2

- . , , , , . . - PING , . , , PING TRACERT, .

+1

(MAX) 30 , , 15. , . , , , -...

+1

, :

  • / ( , ping )
  • , : . HTML , ( ..).

, , 2 - . - 30 .

+1

I understand that this does not directly answer your question, but then the "answer" to this question is a little tough. Anyway, the tool that I used gomez in the past to measure page load time from different parts of the world. It’s free, and if you haven’t done this kind of testing, before it can be useful in terms of giving you a clear idea of ​​what is the typical page load time for a given page from a given location.

+1
source

All Articles