我需要使用.net核心在swagger ui上添加特定标头。有没有办法像这样包含标题?
已经尝试过:
实施IOperationFilter:
public void Apply(Operation operation, OperationFilterContext context)
{
if (operation.Parameters == null)
operation.Parameters = new List<IParameter>();
if (operation.Parameters.All(p => p.Name != "Proxy-Authorization"))
{
operation.Parameters.Add(new NonBodyParameter
{
Name = "Proxy-Authorization",
In = "header",
Description = "Proxy-Authorization token",
Required = true,
Type = "string"
});
}
}
添加安全性定义:
options.AddSecurityDefinition("Proxy-Authorization", new ApiKeyScheme()
{
In = "header",
Description = "Please insert Proxy Authorization Secret into field",
Name = "Proxy-Authorization",
Type = "apiKey"
});
两者都没有用。当我更改标题名称时,一切正常,但是这个特定的标题会从通话中消失。
你有没有遇到过这个问题?怎么解决这个问题?
答案 0 :(得分:2)
来自:https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
禁止标头名称是无法以编程方式修改的HTTP标头名称;特别是,HTTP请求标头名称。
...
禁止标题名称以Proxy-或Sec-开头,或由以下其中一个组成: