Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

javascript - How to send Date header with HTTP request?

I'd like the server to know what time the client thinks it is (for client timestamp date correction).

Arguably, this could be achieved by setting a timestamp in the POST body, but that doesn't cover cases where we have to retry the request at a later time, for example.

I'd argue that the most semantic thing to do is to read the client's time from the request's Date header, which the browser should set just before transmission.

However, I can't figure out how to get the browser to include this header (have tested Chrome and Firefox).

The spec lists Date as a forbidden header name:

These are forbidden so the user agent remains in full control over them.

This is fine, because I'd quite like the browser to be in charge of setting the header.

However, the spec also states:

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.

So the Date header is optional, and only valid on requests with bodies.

So, given that the Date header is optional, and that the browser retains full control of setting the header, is it possible to get a modern browser to send the Date header with a POST request?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...