andrew4582

Url Available

Aug 15th, 2010
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. public static bool UrlAvailable(this string httpUrl)
  2. {
  3. if (!httpUrl.StartsWith("http://") || !httpUrl.StartsWith("https://"))
  4. httpUrl = "http://" + httpUrl;
  5. try
  6. {
  7. HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(httpUrl);
  8. myRequest.Method = "GET"
  9. myRequest.ContentType = "application/x-www-form-urlencoded"
  10. HttpWebResponse myHttpWebResponse =
  11.    (HttpWebResponse)myRequest.GetResponse();
  12. return true;
  13. }
  14. catch
  15. {
  16. return false;
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment