简体   繁体   English

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

[英]Read Browser/Client time from Http Servlet request header

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

I don't believe so. 我不相信。 Unfortunately the HTTP Date header is only sent for PUT or POST messages, and even then it's optional: 不幸的是,HTTP Date标头只发送给PUT或POST消息,即便如此,它也是可选的:

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. 客户端应该只在包含实体主体的消息中发送Date头字段,就像PUT和POST请求一样,即使这样,它也是可选的。 A client without a clock MUST NOT send a Date header field in a request. 没有时钟的客户端不得在请求中发送Date头字段。

If you have control of the client, you could (perhaps) encode it as a separate experimental HTTP header. 如果您可以控制客户端,则可以(可能)将其编码为单独的实验性HTTP标头。 Or add it as a GET parameter etc. 或者将其添加为GET参数等。

You can use javascript and append the time to every request. 您可以使用javascript并将时间附加到每个请求。 Provided that javascript is enabled, you can add the following to your links: 如果启用了javascript,您可以将以下内容添加到您的链接:

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

You can do something similar, if you need timezone information. 如果需要时区信息,可以执行类似的操作。 This question may help. 这个问题可能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM