3

In my WPF application, I need to check the availability of a website at regular interval.

I have this code :

public static string CheckWebsiteAccessibility(Uri uri)
{
    var request = (HttpWebRequest)WebRequest.Create(uri);
    request.Timeout = 15000;
    request.Method = "HEAD";
    var response = (HttpWebResponse)request.GetResponse();
    return response.StatusCode.ToString();
}

That I call every 30 seconds. In localhost it's working, but on another server I sometimes get the error :

The operation has timed out

  1. Is this a good web to check the website availability ?

  2. What can be the reason of the TimeOut (firewall?) and how can I avoid it ?

Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
user3544117
  • 587
  • 4
  • 9
  • 25

1 Answers1

-2

You can try to use Webclient.

And try to test the site with firefox, click F12 and test if you have the same problem.

WebClient client = WebClient.create("adresse");  
Response response = client.get();  

if (response.getStatus() == 200)
{  
    // Web service up and running  
}
else
{  
    // Web service is down 
}
Kevin Hogg
  • 1,771
  • 25
  • 34
bilgin
  • 133
  • 1
  • 13
  • 1
    1- By convention, In C# method names start with UpperCase letter :) (create,get,getStatus) 2- WebClient doesn't have a static *Create* method. 3- WebClient instance doesn't have *Get* method. – L.B Aug 12 '14 at 15:31