为什么浏览器不发送我的显式“ Date”标头?

时间:2019-01-31 12:47:04

标签: javascript http

代码示例:

fetch('https://httpbin.org/get', {
    'headers': {
        'Date': (new Date()).toUTCString(),
    }
})

响应:

{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate, br", 
    "Accept-Language": "en-US,en;q=0.9", 
    "Connection": "close", 
    "Host": "httpbin.org", 
    "Origin": "http://localhost:8000", 
    "Referer": "http://localhost:8000/", 
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 OPR/58.0.3135.53"
  }, 
  "origin": "146.120.13.65", 
  "url": "https://httpbin.org/get"
}

1 个答案:

答案 0 :(得分:4)

Date在获取规范的forbidden header names中列出。

  

这些都是禁止的,因此用户代理仍然可以完全控制它们。

     
      
  • Accept-Charset

  •   
  • Accept-Encoding

  •   
  • Access-Control-Request-Headers

  •   
  • Access-Control-Request-Method

  •   
  • Connection

  •   
  • Content-Length

  •   
  • Cookie

  •   
  • Cookie2

  •   
  • Date

  •   
  • DNT

  •   
  • Expect

  •   
  • Host

  •   
  • Keep-Alive

  •   
  • Origin

  •   
  • Referer

  •   
  • TE

  •   
  • Trailer

  •   
  • Transfer-Encoding

  •   
  • Upgrade

  •   
  • Via

  •