我想检查一个大文件的 URL 是否存在。我正在使用下面的代码,但它太慢了:
public static bool TryGet(string url)
{
try
{
GetHttpResponseHeaders(url);
return true;
}
catch (WebException)
{
}
return false;
}
public static Dictionary<string, string> GetHttpResponseHeaders(string url)
{
Dictionary<string, string> headers = new Dictionary<string, string>();
WebRequest webRequest = HttpWebRequest.Create(url);
using (WebResponse webResponse = webRequest.GetResponse())
{
foreach (string header in webResponse.Headers)
{
headers.Add(header, webResponse.Headers[header]);
}
}
return headers;
}