Hi Ricardo,
if you want to use a webrequest and response to test the internet
connection you could do something like the following, you know that you are
not connected because you will not be alble to resolve the web url and an
exception will be thrown:
bool blnConnected = false;
//choose a site you can count on be up most of the time
HttpWebRequest wr =
(HttpWebRequest)WebRequest.Create("http://www.google.com");
try
{
//try to get response from the website
HttpWebResponse wresp = (HttpWebResponse)wr.GetResponse();
if(wresp.StatusCode == HttpStatusCode.OK)
{
blnConnected = true;
}
}
catch(System.Net.WebException exc)
{
//this will happen if you cannot connect to the site
blnConnected = false;
}
finally
{
wresp.Close();
if(blnConnected)
{
//do connected action
}
else
{
//do unconnected action
}
}
"Ricardo Luceac" wrote:
HI...
I'm making a program to test f my connection to the internet was
alive... I think of make a webrequest and ersponse, but even if my
connection is down doesn't I get a response??? The error 404...
Does you all have an Idea how can I do that???
thx...
*** Sent via Developersdex http://www.developersdex.com ***