I want to check if the URL of a large file exists. I'm using the code below but it is too slow:
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;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…