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