Azure 函数 Return 已弃用 API Header
Azure Function Return Deprecated API Header
我有一个位于代理后面的 Azure Functions。如果返回的 objects 发生更新,我们希望在一段时间后弃用该函数。我正在尝试使用提供的内容 in this solution.
创建一个来自 HTTP Header 的预期内容的响应
Warning: 299 - "Deprecated 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");
}
我得到异常
Exception while executing function: MyAPI -> Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
如何在我的 API Http 响应中附加 "Deprecated" status warning?
将您的线路改为
httpresponse.Headers.Add("Warning", "299 - \"Deprecated API\"");
这里的引号似乎对遵守格式要求很重要。
我有一个位于代理后面的 Azure Functions。如果返回的 objects 发生更新,我们希望在一段时间后弃用该函数。我正在尝试使用提供的内容 in this solution.
创建一个来自 HTTP Header 的预期内容的响应Warning: 299 - "Deprecated 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");
}
我得到异常
Exception while executing function: MyAPI -> Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
如何在我的 API Http 响应中附加 "Deprecated" status warning?
将您的线路改为
httpresponse.Headers.Add("Warning", "299 - \"Deprecated API\"");
这里的引号似乎对遵守格式要求很重要。