如果图像存在,请检查 Azure CDN
Check Azure CDN if image exists
有什么方法可以使用任何 .Net Azure 库来检查 CDN 上是否存在资源。我可以检查一个 blob 是否存在,但没有遇到任何可以检查它是否也存在于 CDN 上的东西
假设您的 BLOB URL 是:
http://foo.blob.core.windows.net/cdn/test.png
并且您的 CDN 端点是 bar.vo.msecnd.net
只需在 http://bar.vo.msecnd.net/cdn/test.png
上执行 HTTP HEAD 请求以查看文件是否存在。
转述 this answer
中提交的代码
HttpWebResponse response = null;
var request = (HttpWebRequest)WebRequest.Create("http://bar.vo.msecnd.net/cdn/test.png");
request.Method = "HEAD";
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
/* do something here */
}
finally
{
// Don't forget to close your response.
if (response != null)
{
response.Close()
}
}
有什么方法可以使用任何 .Net Azure 库来检查 CDN 上是否存在资源。我可以检查一个 blob 是否存在,但没有遇到任何可以检查它是否也存在于 CDN 上的东西
假设您的 BLOB URL 是:
http://foo.blob.core.windows.net/cdn/test.png
并且您的 CDN 端点是 bar.vo.msecnd.net
只需在 http://bar.vo.msecnd.net/cdn/test.png
上执行 HTTP HEAD 请求以查看文件是否存在。
转述 this answer
中提交的代码HttpWebResponse response = null;
var request = (HttpWebRequest)WebRequest.Create("http://bar.vo.msecnd.net/cdn/test.png");
request.Method = "HEAD";
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
/* do something here */
}
finally
{
// Don't forget to close your response.
if (response != null)
{
response.Close()
}
}