我的 ASP.NET 应用程序将 JSON 对象返回给用户,它包含二进制编码数据。因此,我决定启用 HTTP 压缩,问题从 Content-Length 开始。
如果我启用压缩,则 Content-Length 标头将被忽略,而 response 的发送和连接不会立即关闭。发送完所有数据后,连接仍保持打开状态约 15 秒。
我想启用 HTTP 压缩,但不知道如何解决 Content-Length 标头的问题。
context.Response.AddHeader("Content-Length", jsonObject.ToString().Length.ToString());
context.Response.Write(jsonObject);
context.Response.Flush();
context.Response.Close();