有没有办法在不设置 ServicePointManager.DefaultConnectionLimit 的情况下强制在 HttpWebRequest 中进行管道传输?
我想向服务器发送多个 HTTP 请求,尽可能使用管道,否则使用多个 TCP 连接。但是,如果 ServicePointManager.DefaultConnectionLimit 大于 1,HttpWebRequest 似乎会自动使用多个连接。如果我将其设置为 1,我只能将其发送到管道。是否有其他方法可以强制管道化?
I would like to send multiple HTTP requests to a server, using pipelining where possible, and otherwise using multiple TCP connections. However, HttpWebRequest seems to automatically use multiple connections if ServicePointManager.DefaultConnectionLimit is bigger than 1. I can only get it to pipeline if I set this to 1. Is there an alternative way to force pipelining?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法使用 HttpWebRequest 强制进行管道传输。但是,如果服务器符合 1.1 标准,并且您的请求方法是幂等的,那么如果您使用异步并一次向同一服务器发出多个请求,则很有可能会使用管道。您还可以使用具有多个线程的同步模式。关键是一次发出多个请求。
There is no way to force pipelining using HttpWebRequest. However, if the server is 1.1 compliant,and your request method is Idempotent,you can get a high probability of pipelining being used if you use async and issue multiple requests to the same server at a time. You can also use synchronous pattern with multiple threads. The key is to issue more than one request at a time.