How do I check that I have an open network connection and can contact a specific ip address in c#? I have seen example in VB.Net but they all use the \'My\' structure. Than
If you're interested in the HTTP status code, the following works fine:
using System;
using System.Net;
class Program {
static void Main () {
HttpWebRequest req = WebRequest.Create(
"http://www.oberon.ch/") as HttpWebRequest;
HttpWebResponse rsp;
try {
rsp = req.GetResponse() as HttpWebResponse;
} catch (WebException e) {
if (e.Response is HttpWebResponse) {
rsp = e.Response as HttpWebResponse;
} else {
rsp = null;
}
}
if (rsp != null) {
Console.WriteLine(rsp.StatusCode);
}
}
}