如何刷新 HttpListener 响应流?
HttpListener 为您提供响应流,但调用flush 没有任何意义(从来源来看很清楚,因为它实际上什么也没做)。 深入研究 HTTP API 表明这是 HttpListener 本身的限制。
任何人都知道如何刷新 HttpListener 的响应流(可能使用反射或附加 P/Invokes)?
更新:如果您没有刷新选项或定义缓冲区大小的能力,则无法通过 http 流传输任何内容。
HttpListener gives you response stream, but calling flush means nothing (and from sources it's clear, because it's actually doing nothing). Digging inside HTTP API shows that this is a limitation of HttpListener itself.
Anyone knows exactly how to flush response stream of HttpListener (may be with reflection or additional P/Invokes)?
Update: You can't http stream anything if you don't have a flush option or ability to define buffer size.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当 Transfer-Encoding 设置为 Chuncked 时,Flush 仅适用于大多数 System.Net 命名空间,否则会返回整个请求,并且 Flush 实际上不会执行任何操作。 至少这是我在使用 HttpWebResponse 时所经历的。
Flush only works in most of the System.Net namespace when Transfer-Encoding is set to Chuncked, else the whole request is returned and Flush really does nothing. At least this is what I have experienced while working with HttpWebResponse.
我还没有尝试过这个,但是为流响应编写一个单独的 TCP 服务器怎么样? 然后将请求从 HttpListener 转发到“内部”tcp 服务器。 使用此重定向,您可以根据需要将数据流式传输回来。
至于冲洗它,我认为他们唯一的方法是模拟处置,而不是实际处置。 如果您可以侵入 HttpResponseStream 对象,告诉它进行处理、取消设置 m_Closed 标志等,您也许能够刷新流数据。
I've not tried this yet, but how about writing a separate TCP server for streaming responses? Then forward the request from the HttpListener to the "internal" tcp server. Using this redirect you might be able to stream data back as you need.
As for flushing it, they only way I see to do it is to simulate a dispose, without actually disposing. If you can hack into the HttpResponseStream object, tell it to dispose, unset the m_Closed flag, etc, you might be able to flush the streaming data.