根据给定URL判断网络资源(视频,图片等)是否存在的方法
private static bool JudgeFileExist(string url)
{
try
{
//创建根据网络地址的请求对象
System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.CreateDefault(new Uri(url));
httpWebRequest.Method = "HEAD";
httpWebRequest.Timeout = 1000;
//返回响应状态是否是成功比较的布尔值
return (((System.Net.HttpWebResponse)httpWebRequest.GetResponse()).StatusCode == System.Net.HttpStatusCode.OK);
}
catch
{
return false;
}
}