常见的HTTP请求头和响应头

699 阅读2分钟

1. 请求头

请求头描述示例
Accept用户代理支持的MIME类型列表Accept: text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Encoding用户代理支持的压缩方法(优先级)Accept-Encoding: br, gzip, deflate
Accept-Language用户代理期望的语言(优先级)Accept-Language: zh-CN,zh;q=0.9
Cache-Control缓存机制Cache-Control: max-age=0
Connection是否持久连接Connection: keep-alive
CookieHTTP cookies服务器通过Set-Cookie存储到客户端的 Cookie
Host主机名 + 端口号Host: 127.0.0.1:8080
If-Match请求指定标识符资源If-Match: "56a88df57772gt555gr5469a32ee75d65dcwq989"
If-Modified-Since请求指定时间修改过的资源If-Modified-Since: Wed, 19 Oct 2020 17:32:00 GMT
If-None-Match请求非指定标识符资源If-None-Match: "56a88df57772gt555gr5469a32ee75d65dcwq989"
Upgrade-Insecure-Requests客户端优先接受加密和有身份验证的响应,支持CSPUpgrade-Insecure-Requests: 1
User-Agent用户代理User-Agent:Safari/537.36
Vary缓存策略,常用于自适应缓存配置和 SEOVary: User-Agent

2. 响应头

响应头描述示例
Allow服务器支持哪些请求方法Allow: POST,GET,OPTIONS
Cache-Control缓存机制Cache-Control: public, max-age=3600
Connection是否持久连接Connection: keep-alive
Content-Encoding内容编码方式Content-Encoding: br
Content-Type内容的MIME类型Content-Type: text/html; charset=UTF-8
Date报文创建时间Date: Sun, 28 Feb 2021 11:52:51 GMT
Expires资源过期时间Expires: Sun, 28 Feb 2021 12:52:51 GMT
ETag资源标识符ETag: "56a88df57772gt555gr5469a32ee75d65dcwq989"
Set-Cookie服务端向客户端发送CookieSet-Cookie: token=6e204d9b-103a-431e-b8de-ba97b2d1; path=/; HttpOnly