我有一个位于代理后面的 Azure 函数。如果返回的对象发生更新,我们希望在一段时间后弃用该函数。我正在尝试使用提供的 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.
如何附加 "Deprecated" status warning在我的 API Http 响应中?
最佳答案
将线路更改为
httpresponse.Headers.Add("Warning", "299 - \"Deprecated API\"");
引号对于遵守格式要求似乎很重要。
关于c# - Azure函数返回已弃用的API header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49637829/