如何在客户端(使用Flutter Web)验证日期和时间,就像Chrome一样。

huangapple go评论84阅读模式
英文:

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应用程序,我想要在客户端验证日期和时间,就像ChromeWhatsapp一样。为此,我决定在每个请求中发送当前日期和时间到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).

huangapple
  • 本文由 发表于 2023年5月18日 07:11:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76276748.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定