【问题标题】:Azure Function Return Deprecated API HeaderAzure 函数返回不推荐使用的 API 标头
【发布时间】:2018-09-13 05:42:16
【问题描述】:

我有一个位于代理后面的 Azure 函数。如果返回的对象发生更新,我们希望在一段时间后弃用该函数。我正在尝试使用in this solution.

提供的内容来创建包含来自 HTTP 标头的预期内容的响应

警告:299 - “已弃用的 API”

我尝试像这样附加 Azure 函数:

 [FunctionName("MyAPI")]
    public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function,
        "post", Route = null)]
        HttpRequestMessage req,
        TraceWriter log)
    {            
        object response = await someService.Get();
        if (settingsService.IsDeprecated)
        {
            var httpresponse = req.CreateResponse(HttpStatusCode.OK, response, "application/json");
            httpresponse.Content.Headers.Add("Warning", "299 - Deprecated API");
            return httpresponse;
        }
        return req.CreateResponse(HttpStatusCode.OK, response, "application/json");
    }

我得到了异常

执行函数时出现异常:MyAPI -> 错误的标头名称。确保请求标头与 HttpRequestMessage 一起使用,响应标头与 HttpResponseMessage 一起使用,内容标头与 HttpContent 对象一起使用。

如何在我的 API Http 响应中附加 "Deprecated" status warning

【问题讨论】:

    标签: c# azure httpresponse azure-functions


    【解决方案1】:

    将你的线路改为

    httpresponse.Headers.Add("Warning", "299 - \"Deprecated API\"");
    

    引号似乎对于遵守格式要求很重要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-31
      • 2019-05-13
      相关资源
      最近更新 更多