473,388 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Checking if a website is online from a windows app

Hi, I need to write some code to ensure that a website is still
online.

I was just going to write some code (Using System.NET webrequest) to
retrieve the HTML from a website and if the length was 0 then the
website was unavailable;

However, if I get a 404 error then obviously the above would not work.

I also thought of just using a ping but again some websites may be
online but not return a ping request (e.g. Microsoft).

Does anyone have any better ideas about how I can definately tell if a
website is available?

Thanks
Markus

Aug 2 '07 #1
8 2377
Ma*******@gmail.com wrote:
Hi, I need to write some code to ensure that a website is still
online.

I was just going to write some code (Using System.NET webrequest) to
retrieve the HTML from a website and if the length was 0 then the
website was unavailable;

However, if I get a 404 error then obviously the above would not work.

I also thought of just using a ping but again some websites may be
online but not return a ping request (e.g. Microsoft).

Does anyone have any better ideas about how I can definately tell if a
website is available?
I do not see what is wrong with the WebRequest approach !

0 bytes *or* exception means a problem

Arne
Aug 2 '07 #2
Arne Vajhøj wrote:
Ma*******@gmail.com wrote:
>Hi, I need to write some code to ensure that a website is still
online.

I was just going to write some code (Using System.NET webrequest) to
retrieve the HTML from a website and if the length was 0 then the
website was unavailable;

However, if I get a 404 error then obviously the above would not work.

I also thought of just using a ping but again some websites may be
online but not return a ping request (e.g. Microsoft).

Does anyone have any better ideas about how I can definately tell if a
website is available?

I do not see what is wrong with the WebRequest approach !

0 bytes *or* exception means a problem
Code snippet catching exception:

public static bool Test(string url)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "HEAD";
try
{
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
resp.Close();
return true;
}
catch
{
return false;
}
}

Arne
Aug 2 '07 #3
Ma*******@gmail.com wrote:
[...]
Does anyone have any better ideas about how I can definately tell if a
website is available?
First, you need to define "available" and "website". Are you talking
about a specific page at a specific URL? Or simply any response at all
from a web server at a specific address?

For example, a 404 error may in fact give you information that you want,
assuming it came from the web server. The URL might not exist, but at
least you know the server is there (assuming the 404 didn't come from
some intermediate proxy or something).

This seems to me to be a good example of a question that is in need of
more details. What exactly is the information you are trying to find
out here?

Pete
Aug 2 '07 #4
On Aug 2, 10:27 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
Markus...@gmail.com wrote:
[...]
Does anyone have any better ideas about how I can definately tell if a
website is available?

First, you need to define "available" and "website". Are you talking
about a specific page at a specific URL? Or simply any response at all
from a web server at a specific address?

For example, a 404 error may in fact give you information that you want,
assuming it came from the web server. The URL might not exist, but at
least you know the server is there (assuming the 404 didn't come from
some intermediate proxy or something).

This seems to me to be a good example of a question that is in need of
more details. What exactly is the information you are trying to find
out here?

Pete
Hi, very good point Pete. I need to know if the actual website is
available and going with that if the server is unavailable then
obviously the website will be unavailable as well.

Thanks for your help everyone
Markus

Aug 2 '07 #5
Ma*******@gmail.com wrote:
Hi, very good point Pete. I need to know if the actual website is
available and going with that if the server is unavailable then
obviously the website will be unavailable as well.
So maybe you can explain why getting a 404 error isn't useful
information to you. If you get a 404 error, doesn't that mean that the
website is not available, using the definitions you've provided here?

There are a variety of errors that you might get trying to retrieve a
specific URL. However, it seems to me that as long as you don't get any
error, the website is available, and if you do get any error, it's not.

If that's not suitable for your needs, IMHO you still need to be more
specific about what information it is exactly that you want.

Pete
Aug 2 '07 #6
On Aug 2, 10:57 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
Markus...@gmail.com wrote:
Hi, very good point Pete. I need to know if the actual website is
available and going with that if the server is unavailable then
obviously the website will be unavailable as well.

So maybe you can explain why getting a 404 error isn't useful
information to you. If you get a 404 error, doesn't that mean that the
website is not available, using the definitions you've provided here?

There are a variety of errors that you might get trying to retrieve a
specific URL. However, it seems to me that as long as you don't get any
error, the website is available, and if you do get any error, it's not.

If that's not suitable for your needs, IMHO you still need to be more
specific about what information it is exactly that you want.

Pete
Hi Pete, a 404 error is fine but I am not sure if a 404 will return a
string length 0(?) from the webrequest. If so checking the sring
length would fail even though the website was still alive.

This post was to ask if I am doing things the right way or if someone
can recommend a better way to do things.

For all I know there may have been an obscure method buried deep in
the .NET 2.0 framework which did what I am going to do manually :)

Thanks for ally our help
Mark

Aug 2 '07 #7
Ma*******@gmail.com wrote:
Hi Pete, a 404 error is fine but I am not sure if a 404 will return a
string length 0(?) from the webrequest. If so checking the sring
length would fail even though the website was still alive.
Why does it matter? If you get a 404 error, then that itself tells you
the information you want to know. Why would you care about any data
past the error response, even if it exists?
This post was to ask if I am doing things the right way or if someone
can recommend a better way to do things.
Well, I would agree that simply checking the length of the response
isn't an appropriate solution.
For all I know there may have been an obscure method buried deep in
the .NET 2.0 framework which did what I am going to do manually :)
I don't have any first-hand experience with the HttpWebRequest class,
but it looks to me as though if any HTTP error occurs when you call
GetResponse(), a WebException will be thrown. You can look at the
Response property of the WebException to see the details of the error,
but in your case the mere fact that the exception is thrown would
probably suffice.

Are you finding that you have a situation when the web site is not
available and yet an exception is not thrown when you call GetResponse()?

Pete
Aug 2 '07 #8
On Aug 2, 4:17 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
Markus...@gmail.com wrote:
Hi Pete, a 404 error is fine but I am not sure if a 404 will return a
string length 0(?) from the webrequest. If so checking the sring
length would fail even though the website was still alive.

Why does it matter? If you get a 404 error, then that itself tells you
the information you want to know. Why would you care about any data
past the error response, even if it exists?
This post was to ask if I am doing things the right way or if someone
can recommend a better way to do things.

Well, I would agree that simply checking the length of the response
isn't an appropriate solution.
For all I know there may have been an obscure method buried deep in
the .NET 2.0 framework which did what I am going to do manually :)

I don't have any first-hand experience with the HttpWebRequest class,
but it looks to me as though if any HTTP error occurs when you call
GetResponse(), a WebException will be thrown. You can look at the
Response property of the WebException to see the details of the error,
but in your case the mere fact that the exception is thrown would
probably suffice.

Are you finding that you have a situation when the web site is not
available and yet an exception is not thrown when you call GetResponse()?

Pete
Hi Pete, I'll give it a whirl and see how I go. Thanks again for your
help

Regards
Markus

Aug 2 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Mickel Grönroos | last post by:
Hi all, I have a silly question. Is there are simple way to check if the computer is connected to the Internet? It seems this should be a pretty straight-forward thing to do, but as I am totally...
3
by: Sean Walsh | last post by:
I want to perform the following manual steps programatically. 1) I go to a secure website (https://secure.xxx.yyy) where I am prompted for a user name and password with windows authorization...
7
by: wrytat | last post by:
Hi! I'm very new to ASP.NET and really need some good advice from experts here. I'm creating a web application for my company now. This application has 2 parts. 1 part for the customers to...
3
by: John Holmes | last post by:
We have a couple of websites on our Intranet IIS server. We use the default website for some vended web apps, but the majority of our intranet exists on another IIS configured website. The problem...
7
by: Jonathan Wood | last post by:
Greetings, I have extensive programming experience (nearly 20 years) but have yet to write a full-blown Web application. In fact, I have done hardly any server/client/database programming at...
10
by: JP Bless | last post by:
Hi all, I have a database Access/MSDE and would like to have a website so users can search the data and update some records/fields through the website.... And I have high speed internet...
4
by: Jigar A. Thakor | last post by:
how to create online shopping website.. ?? any architecture ?? How to design any guidlines ? and what is verisign ?? other secure protection needed ?? i want to develop in C#,Asp.net,Sql Server...
10
by: TS | last post by:
i just noticed the website i created in VS 2005 is running on a different port than the default. I see that it is running on the local web server, and also that the website i created isn't in IIS....
9
by: xhe | last post by:
Hi, I need to program to check the validity of IP address through PHP Initially I used this one: $url="http://www.ntc.gov.au/ViewPage.aspx? page=A02400304500100020"; $fp=fopen($url,"r");...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.