// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Net; namespace E { public class WebTest { public static void Test(string url) { try { WebRequest wreq = WebRequest.Create(url); WebResponse wresp = wreq.GetResponse(); if(wresp is HttpWebResponse) { HttpWebResponse hwresp = (HttpWebResponse)wresp; if(hwresp.StatusCode == HttpStatusCode.OK) { Console.WriteLine(url + " is working"); } else { Console.WriteLine(url + " has small problems: " + hwresp.StatusDescription); } } else { Console.WriteLine(url + " is not a HTTP URL"); } } catch(WebException wex) { if(wex.Response == null) { Console.WriteLine(url + " has big problems: " + wex.Message); } else { if(wex.Response is HttpWebResponse) { HttpWebResponse hwresp = (HttpWebResponse)wex.Response; if(hwresp.StatusCode == HttpStatusCode.OK) { Console.WriteLine(url + " is working"); } else { Console.WriteLine(url + " has small problems: " + hwresp.StatusDescription); } } else { Console.WriteLine(url + " is not a HTTP URL"); } } } } } class MainClass { public static void Main(string[] args) { WebTest.Test("http://arne/index.html"); WebTest.Test("http://arne/notexist.html"); WebTest.Test("http://notexist/index.html"); } } }