从 Http Servlet 请求标头读取浏览器/客户端时间

发布于 2024-07-29 17:20:31 字数 43 浏览 6 评论 0原文

当向 servlet 发出请求时是否可以读取浏览器(客户端计算机)时间?

Is it possible to read the Browser(Client machine) time when a request is made to the servlet?

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

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

发布评论

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

评论(2

温柔戏命师 2024-08-05 17:20:31

我不相信是这样。 不幸的是,HTTP Date 标头仅针对 PUT 或POST 消息,即使如此,它也是可选的:

客户端应该只发送日期标头
消息中包含的字段
实体主体,如 PUT 的情况
和 POST 请求,即使如此
选修的。 没有时钟的客户端
不得在
请求。

如果您可以控制客户端,您(或许)可以将其编码为单独的实验性 HTTP 标头。 或者将其添加为 GET 参数等。

I don't believe so. Unfortunately the HTTP Date header is only sent for PUT or POST messages, and even then it's optional:

Clients SHOULD only send a Date header
field in messages that include an
entity-body, as in the case of the PUT
and POST requests, and even then it is
optional. A client without a clock
MUST NOT send a Date header field in a
request.

If you have control of the client, you could (perhaps) encode it as a separate experimental HTTP header. Or add it as a GET parameter etc.

誰ツ都不明白 2024-08-05 17:20:31

您可以使用 javascript 并将时间附加到每个请求。 如果启用了 javascript,您可以将以下内容添加到您的链接中:

link = link + "?date="+(new Date()).getTime()

如果您需要时区信息,您可以执行类似的操作。 这个问题可能会有所帮助。

You can use javascript and append the time to every request. Provided that javascript is enabled, you can add the following to your links:

link = link + "?date="+(new Date()).getTime()

You can do something similar, if you need timezone information. This question may help.

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