英文:
How to validate date and time on the client side like Chrome does, using Flutter Web
问题
I have a Flutter Web application, and I want to validate the date and time of the Client side, just like Chrome or Whatsapp does. To do this, I decided to send in each request the current date and time within the headers, and validate it on the Server, but for some reason I received the error Refused to set unsafe header "date" in the browser console, and the field date is not found within the headers on the Server side. Could someone provide me with the correct way to do what I want, or the solution to my problem?
我有一个Flutter Web应用程序,我想要在客户端验证日期和时间,就像Chrome或Whatsapp一样。为此,我决定在每个请求中发送当前日期和时间到headers,并在服务器端进行验证。但是出现了错误:在浏览器控制台中显示拒绝设置不安全的标头 "date",而在服务器端的headers中找不到date字段。有人能告诉我实现我想要的方式,或者解决我的问题吗?
英文:
I have a Flutter Web application, and I want to validate the date and time of the Client side, just like Chrome or Whatsapp does. To do this, I decided to send in each request the current date and time within the headers, and validate it on the Server, but for some reason I received the error Refused to set unsafe header "date" in the browser console, and the field date is not found within the headers on the Server side. Could someone provide me with the correct way to do what I want, or the solution to my problem?
I have already searched several answers but I still do not have the solution, for example one of the most recent
答案1
得分: 1
标题名Date是保留的 - 只有浏览器可以设置它。请参见XMLHttpRequest规范的第4.6.2节以获取完整列表。您能将标题名更改为,比如,Request-Date吗?(当然,似乎很容易伪造。)
另外,您可以将值作为GET的查询参数发送,或者作为POST的主体(表单或JSON)。
英文:
The header name Date is reserved - only the browser may set it. See Section 4.6.2 of the XMLHttpRequest spec for the complete list. Can you change your header name to, say, Request-Date? (Of course, it seems it would be easy to forge.)
Also, rather than sending the value as a header, you could send it as a query parameter of a GET, or in the body of a POST (form or JSON).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论