首页 文章

Azure函数返回不推荐使用的API标头

提问于
浏览
0

我有一个Azure功能,位于代理后面 . 如果对返回的对象进行更新,我们希望在一段时间后弃用该函数 . 我正在尝试使用提供的内容从HTTP标头创建具有预期内容的响应in this solution.

警告: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 - > Misused header name . 确保请求标头与HttpRequestMessage一起使用,响应标头与HttpResponseMessage一起使用,内容标头与HttpContent对象一起使用 .

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

1 回答

  • 2

    将您的行更改为

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

    引号似乎很重要,以遵守格式要求 .

相关问题