如何关闭持久代理连接

发布于 2024-10-17 03:13:26 字数 816 浏览 3 评论 0原文

这是此问题的后续内容了解如何在 HttpWebRequest 上打开 Connection: Keep-Alive 标头。

我已成功从 Web 服务调用中禁用 Connection: Keep-Alive 标头,但当我使用代理时,它还会发送 CONNECT xxx.xxxxx.xx:443 HTTP/1.1 code> 在调用发送到服务器之前发送给代理。

通过此 CONNECT 调用,将发送一堆标头:

System.Net Information: 0 : [5420] ConnectStream#33166512 - 发送标头
{
代理授权:基本 xxxxxxxxxxxxxxx==
主机:xxx.xxxxx.xx
代理连接:保持活动
}。

我想摆脱 Keep-Alive 并将其更改为 Close 但无法找到如何控制此标头。如何更改或禁用 Proxy-Connection 标头?

编辑:
谷歌搜索后,我发现我必须设置 webRequest.Connection = "Close";webRequest.Connection = null;,但这些会导致参数异常。

This is a follow up on this question on how to turn of Connection: Keep-Alive headers on HttpWebRequest.

I have successfully disabled the Connection: Keep-Alive headers from my Web service call, but when I use a proxy it also sends a CONNECT xxx.xxxxx.xx:443 HTTP/1.1 to the proxy before the call is sent to the server.

With this CONNECT call a bunch of headers are sent:

System.Net Information: 0 : [5420] ConnectStream#33166512 - Sending headers
{
Proxy-Authorization: Basic xxxxxxxxxxxxxxx==
Host: xxx.xxxxx.xx
Proxy-Connection: Keep-Alive
}.

I want to get rid of the Keep-Alive and change it to Close but cannot find out how to control this header. How do I change or disable the Proxy-Connection header?

Edit:
Googleing around I figured that I have to set the webRequest.Connection = "Close"; or webRequest.Connection = null;, but those results in an argument exception.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木落 2024-10-24 03:13:26

显然不可能更改 Proxy-Connection 标头。

我试图实现的结果(在客户端和代理之间的负载平衡器在 2 分钟不活动后杀死它之前关闭与代理的 tcp 连接)是通过设置

ServicePointManager.MaxServicePointIdleTime = 100000;

实现的ServicePointManager 会在 100 秒后关闭底层连接,早在它被负载均衡器终止之前,并在必要时创建一个新连接。

Appareantly it is not possible to change the Proxy-Connection header.

The result that I was trying to achieve (close the tcp connection to the proxy before the load-balancer between client and proxy kills it after 2 minutes of inactivity) was realized by setting

ServicePointManager.MaxServicePointIdleTime = 100000;

The ServicePointManager closes the underlying connection after 100 seconds, well before it is killed by the load-balancer and creates a new one when necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文