Determine Whether a URL Is Valid

Use this Boolean function to determine whether a URL is valid:

public static bool checkUrl(string url) {  bool rt = false;  if (url.StartsWith("www."))  {   url = "http://" + url;  }  HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);   HttpStatusCode code = new HttpStatusCode();   HttpWebResponse myResponse = null;   try  {    myResponse = (HttpWebResponse)myRequest.GetResponse();   code = myResponse.StatusCode;   rt = true;  }  catch(WebException err)  {   rt = false;  }   return rt;}
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: