我有一个 dotnet 框架应用程序,它对运行 Apache 的远程服务器执行 POST api 请求。它间歇性地失败并出现以下错误:
The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
当通过保活 TLS 连接完成对服务器的第二次请求时,这种情况会发生,因此在负载较重的生产系统中发生的频率更高,而在开发环境中发生的频率较低或根本不发生。
我们尝试过:
- 禁用
Expect: 100-Continue
标头行为 (ServicePoint.Expect100Continue = false
) - 启用 TCP 保持活动 (
ServicePoint.SetTcpKeepAlive()
)
禁用 HTTP keep-alive 似乎可以解决该问题。( HttpWebRequest.KeepAlive = false
)
有没有办法在不禁用http keep-alive的情况下解决这个问题?