如何检查图像是否存在于 http://someurl/myimage.jpg在 C#/ASP.NET 中 似乎应该有一种方法来检查这一点——但我找不到。
我找到了 this , 但它并没有真正回答问题。
最佳答案
这段代码应该可以工作:
private static bool UrlExists(string url)
{
try
{
new System.Net.WebClient().DownloadData(url);
return true;
}
catch (System.Net.WebException e)
{
if (((System.Net.HttpWebResponse)e.Response).StatusCode == System.Net.HttpStatusCode.NotFound)
return false;
else
throw;
}
}
关于c# - 如何在 C#/ASP.NET 中检查图像是否存在于 http ://someurl/myimage. jpg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1639878/