提前关闭与浏览器的连接并返回响应状态

发布于 2024-12-05 18:25:27 字数 641 浏览 2 评论 0原文

我正在项目中实现一个自定义 IHttpModule,它过滤文件上传并提供上传状态。 我希望自定义模块尽早关闭连接(不想接收对方发送的所有数据,允许很大,节省传入带宽)。

是否可以使用 HTTP 协议?

我尝试发送“ContentLength:0”和“Connection:close”标头,刷新响应,关闭连接(HttpWorkerRequest.CloseConnection)。

workerRequest.SendStatus(400, "Bad request");
workerRequest.SendKnownResponseHeader(HttpWorkerRequest.HeaderContentLength, "0");
workerRequest.SendKnownResponseHeader(HttpWorkerRequest.HeaderConnection, "close");
workerRequest.FlushResponse(false);
workerRequest.CloseConnection();
((HttpApplication)sender).CompleteRequest();

浏览器/Firefox 响应显示“连接重置”错误消息。 没有任何从服务器接收任何数据/标头/状态的迹象。

提前致谢。

I am implementing a custom IHttpModule in a project, which filter file uploading and provide upload status.
I want the custom module to close the connection early (don't want to receive all the data the other side send, which is allowed to be big, save the incoming bandwidth).

Is it a possibility using HTTP protocol?

I tried sending "ContentLength: 0" and "Connection: close" header, flush the response, close the connection (HttpWorkerRequest.CloseConnection).

workerRequest.SendStatus(400, "Bad request");
workerRequest.SendKnownResponseHeader(HttpWorkerRequest.HeaderContentLength, "0");
workerRequest.SendKnownResponseHeader(HttpWorkerRequest.HeaderConnection, "close");
workerRequest.FlushResponse(false);
workerRequest.CloseConnection();
((HttpApplication)sender).CompleteRequest();

The browser/firefox response is displaying the "Connection reset" error message.
Without any sign of receiving any data/header/status from the server.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城仅有旧梦在 2024-12-12 18:25:27

http 客户端仅在完成发送数据后才期望响应。您应该修改客户端以发出多个小尺寸请求,以便可以向其发送响应,而不是让服务器关闭连接(这将不起作用,并且正如您已经测试过的那样不起作用)。

检查 http://slfileupload.codeplex.com/ 获取通常如何完成的示例。

An http client expects response only after it has completed sending the data. You should modify the client to make multiple requests of small sizes so a response can be sent to it instead of having server close the connection (which will not work and isn't working as you've tested already).

Check the http handler implemented in http://slfileupload.codeplex.com/ for a sample of how it is typically done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文