Im using code like this to check if URL’s are real and exist:
its working fine generally, but it’s not working for youtube urls..
eg this valid url: http://www.youtube.com/watch?v=c4IBN5OAdZc
Utils.UrlExists(uri)
public static bool UrlExists(string url)
{
using (var client = new MyClient())
{
client.HeadOnly = true;
// fine, no content downloaded
try
{
string s1 = client.DownloadString(url);
return true;
}
catch { return false; }
}
}
class MyClient : WebClient
{
public bool HeadOnly { get; set; }
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest req = base.GetWebRequest(address);
if (HeadOnly && req.Method == "GET")
{
req.Method = "HEAD";
}
return req;
}
}
erics comment was the answer. If he puts an answer I’ll mark it as correct. in the meantime I’ll mark this as correct