【问题标题】:Check Azure CDN if image exists如果映像存在,请检查 Azure CDN
【发布时间】:2016-04-16 07:46:53
【问题描述】:

有什么方法可以使用任何 .Net Azure 库来检查 CDN 上是否存在资源。我可以检查一个 blob 是否存在,但没有遇到任何可以检查它是否也存在于 CDN 上的东西

【问题讨论】:

    标签: c# .net azure cdn


    【解决方案1】:

    假设您的 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()
        }
    }
    

    【讨论】:

    • 但这不会导致CDN获取图片吗?
    • 不,因为它是 HEAD 而不是 GET,它不是 fethcing img 响应体
    猜你喜欢
    • 1970-01-01
    • 2016-08-20
    • 2012-03-04
    • 2014-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 2018-06-26
    相关资源
    最近更新 更多