每个 WebRequest.Create() 都有不同的 TCP 连接
我有一个 .net windows 服务,它通过从服务器下载文件来测试网络性能。我正在使用 (HttpWebRequest)WebRequest.Create(uri)
创建 HTTP 请求。
该服务由定时器控制。当计时器间隔相对较小时,HTTP 请求会被服务器阻止。
通过查看数据包分析器,似乎 TCP 连接已被重用。如何为每个 WebRequest 请求“新”TCP 连接?
I have a .net windows service that test network performance by downloading files from a server. I'm using (HttpWebRequest)WebRequest.Create(uri)
to create the HTTP requests.
This service is controlled by a timer. When the timer interval is relatively small, the HTTP requests get blocked by the server.
By looking at packet analyzer, it seems like the TCP connection have been reused. How to request a 'new' TCP connection for each WebRequest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试设置
HttpWebReqeuest.KeepAlive
为false
。Try setting
HttpWebReqeuest.KeepAlive
tofalse
.我相信您面临着 HTTP 保持活动状态,因此您必须以某种方式强制
WebClient
不要使用它。这是从客户端作为connection: keep-alive
标头发送的,如果服务器支持,则保持连接。在 Wiki 中查看更多信息: http://en.wikipedia.org/wiki/HTTP_persistent_connection所以也许如果您发送
connection:close
您会在每个请求上获得一个新的 TCP 会话。I believe you are facing a HTTP-keep alive, so you have to somehow force the
WebClient
not to use it. This is sent asconnection: keep-alive
header from the client and, if the server supports it, connection is kept. See more in Wiki: http://en.wikipedia.org/wiki/HTTP_persistent_connectionSo maybe if you send
connection:close
you get a new TCP session on each request.