Search code examples
c#web-servicesweb-applicationshttpwebrequesthttpwebresponse

Checking a Web Application for a Response using HttpWebRequest/Response C#


GOAL
Currently, I'm working on a watchdog program for a project management internet application. It is a subscription based web application that is located on a server somewhere over the rainbow (not a company based server). For whatever reason, the company that owns this application does not watch their own program to make sure it's responsive. Basically, it is going to be down until some subscriber notices it and informs the company. My manager is not having it so therefore I get to come up with a watchdog program to constantly check if the application is working properly.

MY QUESTION
I've been exploring the System.Net.NetworkInformation namespace, specifically HttpWebResponse/Request classes. The definition of the GetResponse method is "Returns a response from an Internet resource." I feel like this is a very general definition so I'm not quite sure if it's enough to deduce whether this web application is working. My question is what is the GetReponse method of a HttpWebRequest object actually doing? Is this what I want to use to create my watchdog program? And if not, do you have any suggestions?


Solution

  • GetResponse is returning the web server's response to the request that you made for a web page or other resource. What you want to do is check the status of the response to your request, presumably to some page that indicates if the app is working. So you try to hit the page with your web request, the response status is OK, you keep on trucking. Otherwise, you would do something in response to the error like send an email to the company that hosts the app.

    This question has answered how that looks in code:

    How to get error information when HttpWebRequest.GetResponse() fails