【发布时间】:2018-01-27 10:25:46
【问题描述】:
我尝试使用 GET 和 POST 制作简单的 Web API 应用程序。当我响应 GET 请求时:
{
"status": "OK",
"headers":
{
"Date": "Fri, 18 Aug 2017 16:50:38 GMT",
"Transfer-Encoding": "chunked",
"Connection": "close",
"Content-Type": "application/json; charset=utf-8",
"Server": "Kestrel"
},
"body": "....",
"code": 200,
"protocol": "HTTP/1.1"
}
但我想制作"Connection": "keep-alive",而不是"Connection": "close",所以我更改了我的配置。
Startup.cs:
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
app.UseSession();
app.Run(async (context) =>
{
context.Response.Headers[HeaderNames.Connection] = "Keep-Alive";
});
}
但是,我收到了"Connection": "close" 的回复。
知道如何更改为"keep-alive" 设置吗?
【问题讨论】:
标签: c# asp.net-core http-headers keep-alive asp.net-core-webapi