如何关闭持久代理连接
这是此问题的后续内容了解如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然不可能更改 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.