跳到主要内容

http 常见的 header 有哪些?

常见的 Request Headers

  • Accept 浏览器可以接收的数据格式
  • Accept-Encoding 浏览器可接收的压缩算法,如 gzip
  • Accept-Languange 浏览器可接收的语言,如 zh-CN
  • Connection:keep-alive 一次 TCP 连接重复使用
  • cookie
  • Host 域名
  • User-Agent 简称 UA, 浏览器信息
  • Content-type 发送数据的格式,如 application/json

常见的 Response Headers

  • Content-type 返回数据的格式,如 application/json
  • Content-length 返回数据的大小,多少字节
  • Content-Encoding 返回数据的压缩算法,如 gzip
  • Set-Cookie

自定义 header

如:http://axios-js.com/docs/#Request-Config

// `headers` are custom headers to be sent
headers: {'X-Requested-With': 'XMLHttpRequest'}

缓存相关的 headers

  • Cache-Control

  • Expires

  • Last-Modified

  • If-Modified-Since

  • Etag

  • If-None-Match