我使用httpwebrequest写了一个404死链检查的方法如下: public static bool UrlFound(string url)
{
HttpWebResponse response = null;
try
{
HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(new Uri(url));
response = (HttpWebResponse)request.GetResponse();
return response.StatusCode == HttpStatusCode.OK;
}
catch (WebException ex)
{
Console.WriteLine(ex.ToString());
HttpWebResponse errorResponse = ex.Response as HttpWebResponse;
if (errorResponse != null)
if (errorResponse.StatusCode == HttpStatusCode.NotFound)
return false;
}
finally
{
if (response != null)
response.Close();
}
return false;
}
然后,我使用paraell中对一组url进行检查:
然而,会出现某些正常的图片返回404。而这些图片是可以打开的。