【发布时间】:2016-04-16 07:46:53
【问题描述】:
有什么方法可以使用任何 .Net Azure 库来检查 CDN 上是否存在资源。我可以检查一个 blob 是否存在,但没有遇到任何可以检查它是否也存在于 CDN 上的东西
【问题讨论】:
有什么方法可以使用任何 .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()
}
}
【讨论】: