如何强制 IIS 发送响应标头而不发送响应正文并关闭连接
我正在尝试使用 IIS 通过 HTTP 将动态生成的数据流式传输到客户端,并且连接必须长时间保持打开状态,并且服务器在执行耗时的操作时将定期向客户端发送状态更新。
这必须全部在一个请求中处理,但我使用的是 WebClient.OpenRead()
流,在发送标头之前无法打开该流。
如何强制 IIS 将标头发送到客户端,然后发送响应正文?
I am trying to stream dynamically generated data to a client over HTTP using IIS, and the connection has to remain open for a long period of time, and the server will send periodic status updates to the client while it is performing a time-consuming operation.
This MUST all be handled within ONE request, but I am using a WebClient.OpenRead()
stream, which cannot be opened until the headers are sent.
How can I force IIS to send headers to the client, and later send a response body?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常可以通过将 KeepAlive 设置为 true 并将 Expect 标头设置为“100 并继续”来实现此行为。通过这样做,服务器将发送结果代码为 100 的标头。
我不确定使用 WebClient 是否可以实现这一点。
使用 HttpWebRequest 来设置上述值。事实上,WebClient 没有做任何神奇的事情,只是使用 GET 来获取数据。下面是Reflector中调用OpenRead的代码:
This behaviour is normally achievable by setting KeepAlive to true and setting Expect header to "100 and continue". By doing this, server will send the headers with result code 100.
I am not sure if this is possible using WebClient.
Use HttpWebRequest instead to be able to set the values above. In fact WebClient does nothing magical but using GET to get the data. Here is the code for calling OpenRead in Reflector: