判断远程文件是否存在
HttpWebRequest req = null;
HttpWebResponse res = null;
try
{
req = (HttpWebRequest)WebRequest.Create(uri);
req.Method = "HEAD";
req.Timeout = 100;
res = (HttpWebResponse)req.GetResponse();
return (res.StatusCode == HttpStatusCode.OK);
}
catch
{
return false;
}
finally
{
if (res != null)
{
res.Close();
res = null;
}
if (req != null)
{
req.Abort();
req = null;
}
}