常见的HTTP消息头
概念
HTTP 消息头允许客户端和服务器通过 request和 response 传递附加信息。一个请求头由名称(不区分大小写)后跟一个冒号“:”,冒号后跟具体的值(不带换行符)组成。
HTTP 消息头分为 请求头和响应头。
HTTP请求头
| 请求头 | 含义 | 示例 |
|---|---|---|
| Accept | 可接收的数据格式 | Accept: text/plain |
| Accept-Charset | 可接受的字符集 | Accept-Charset: utf-8 |
| Accept-Encoding | 可接收的压缩算法 | Accept-Encoding: gzip, deflate |
| Accept-Language | 浏览器可接收的语言 | Accept-Language: zh-CN |
| Authorization | 服务器用于验证用户代理身份的凭证 | Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l |
| Cache-Control | 是否使用缓存机制 | Cache-Control: no-cache |
| Connection | 决定当前的事务完成后,是否会关闭网络连接 | Connection: keep-alive |
| Cookie | 请求发送时,会把保存在该请求域名下的所有 cookie 值一起发送给服务器 | Cookie: PHPSESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1; |
| Content-Length | 请求体的长度 | Content-Length: 119 |
| Content-Type | 发送数据的格式 | Content-Type: text/html; charset=UTF-8 |
| Date | 报文创建的日期和时间 | Date: Wed, 21 Oct 2015 07:28:00 GMT |
| Expect | 服务器只有在满足此期望条件的情况下才能妥善地处理请求 | Expect: 100-continue |
| Host | 指明了请求将要发送到的服务器主机名和端口号 | Host: developer.mozilla.org |
| Referer | 包含一个 URL,用户从该 URL 代表的页面出发访问当前请求的页面 | Referer: https://www.lqzww.top |
| User-Agent | 浏览器信息 | User-Agent: Mozilla/5.0… |
HTTP响应头
| 响应头 | 含义 | 示例 |
|---|---|---|
| Cache-Control | 告诉所有的缓存机制是否可以缓存及哪种类型 | Cache-Control: max-age=1200 |
| Content-Type | 返回数据的格式 | Content-Type: text/html; charset=utf-8 |
| Content-Length | 返回数据的大小 | Content-Length: 120 |
| Content-Encoding | 返回数据的压缩算法 | Content-Encoding: gzip |
| Date | 原始服务器消息发出的时间 | Date: Wed, 21 Oct 2015 07:28:00 GMT |
| Expires | 响应过期的日期和时间 | Expires: Wed, 21 Oct 2015 07:28:00 GMT |
| ETag | 资源的唯一标识 | ETag: W/“0815” |
| Last-Modified | 请求资源的最后修改时间 | Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT |
| Location | 用来重定向接收方到非请求URL的位置来完成请求或标识新的资源 | Location: http://www.lqzww.top |
| Set-Cookie | 服务器端向客户端发送cookie | Set-Cookie: sessionid=38afes7a8; HttpOnly; Path=/ |
参考资料
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 LqZww's blog!
评论
ValineLivere









