HTTP 服务器检测到来自 HTTP 客户端的网络连接中断

发布于 2024-10-08 04:19:57 字数 168 浏览 2 评论 0原文

我有一个 Web 应用程序,在向服务器发出 HTTP 请求后,客户端在客户端完全接收到响应之前退出(或网络连接中断)。

在这种情况下,应用程序的服务器端需要执行一些清理工作。 HTTP 协议中是否有内置方法来检测这种情况。服务器如何知道客户端是否仍在等待响应或已经退出?

谢谢 维杰·库马尔

I have an web application in which after making a HTTP request to the server, the client quits ( or network connection is broken) before the response was completely received by the client.

In this scenario the server side of the application needs to do some cleanup work. Is there a way built into HTTP protocol to detect this condition. How does the server know if the client is still waiting for the response or has quit?

Thanks
Vijay Kumar

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

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

发布评论

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

评论(2

何其悲哀 2024-10-15 04:19:57

不,协议中没有内置任何内容来执行此操作(毕竟,您无法判断客户端本身是否已收到响应,或者只是下游代理收到了响应)。

只需让您的客户端发出第二个请求以确认其已收到并存储原始响应即可。如果您没有看到及时的确认,请运行清理。

不过,请确保您了解两位将军问题的含义。

No, there is nothing built in to the protocol to do this (after all, you can't tell whether the response has been received by the client itself yet, or just a downstream proxy).

Just have your client make a second request to acknowledge that it has received and stored the original response. If you don't see a timely acknowedgement, run the cleanup.

However, make sure that you understand the implications of the Two Generals' Problem.

讽刺将军 2024-10-15 04:19:57

您可能遇到网络问题...通常,当您向服务器发送 HTTP 请求时,首先发送标头,然后发送 POST 的内容(如果是 post 方法)。同样,服务器以标头和文档正文进行响应。标题中的第一行是状态。通常,状态 200 是成功状态,如果您得到该状态,那么获取文档的其余部分应该没有问题。检查此内容以获取有关 HTTP 响应状态标头的详细信息 http://www.w3.org /Protocols/rfc2616/rfc2616-sec6.html

LE:
抱歉,读错了你的问题。基本上,当用户断开连接时,您没有触发器。如果您使用 OOP,您可以使用类的析构函数来清理您需要清理的任何内容。

You might have a network problem... usualy, when you send a HTTP request to the server, first you send headers and then the content of the POST (if it is a post method). Likewise, the server responds with the headers and document body. The first line in the header is the status. Usually, status 200 is the success status, if you get that, then there should be no problem getting the rest of the document. Check this for details on the HTTP response status headers http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html

LE:
Sorry, missread your question. Basically, you don't have a trigger for when the user disconnects. If you use OOP, you could use the destructor of a class to clean whatever it is you need to clean.

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