HTTP Headers文档、HTTP Headers各项含义、HTTP Headers详解

请求头 (Request Headers)

Header名称 说明 示例
Accept 告诉服务器,客户端能够处理的内容类型,按优先级排列 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset 告诉服务器,客户端能够处理的字符集类型 Accept-Charset: utf-8, iso-8859-1;q=0.5
Accept-Encoding 告诉服务器,客户端能够处理的编码方式 Accept-Encoding: gzip, deflate, br
Accept-Language 告诉服务器,客户端能够处理的语言 Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Authorization 包含用于服务器验证用户身份的凭据 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Cache-Control 指定请求和响应遵循的缓存机制 Cache-Control: no-cache, no-store, must-revalidate
Connection 控制网络连接在当前事务完成后是否仍然保持打开状态 Connection: keep-alive
Content-Length 请求体的长度(字节) Content-Length: 348
Content-Type 请求体的媒体类型 Content-Type: application/json; charset=utf-8
Cookie 包含存储在客户端的HTTP cookie Cookie: sessionid=abc123; csrftoken=xyz789
Host 指定服务器的域名和端口号 Host: www.example.com:8080
If-Modified-Since 只有在指定时间后资源被修改过才返回资源 If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT
If-None-Match 只有在ETag不匹配的情况下才返回资源 If-None-Match: "686897696a7c876b7e"
Referer 告诉服务器请求是从哪个页面发起的 Referer: https://www.example.com/page.html
User-Agent 用户代理字符串,包含客户端信息 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
X-Forwarded-For 标识通过HTTP代理或负载均衡方式连接到Web服务器的客户端的原始IP地址 X-Forwarded-For: 203.0.113.195, 70.41.3.18
X-Requested-With 标识Ajax请求,通常值为XMLHttpRequest X-Requested-With: XMLHttpRequest

响应头 (Response Headers)

Header名称 说明 示例
Access-Control-Allow-Origin 指示响应的资源是否可以被给定的来源共享 Access-Control-Allow-Origin: https://example.com
Access-Control-Allow-Methods 指明实际请求所允许使用的HTTP方法 Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Cache-Control 告诉浏览器和其他缓存该如何缓存响应 Cache-Control: public, max-age=3600
Content-Disposition 指示如何显示附加的文件 Content-Disposition: attachment; filename="file.pdf"
Content-Encoding 告知客户端服务器对实体消息体采用的编码方式 Content-Encoding: gzip
Content-Length 响应体的长度(字节) Content-Length: 1024
Content-Security-Policy 允许网站管理员控制用户代理为指定的页面加载哪些资源 Content-Security-Policy: default-src 'self'
Content-Type 告诉客户端实际返回的内容类型 Content-Type: text/html; charset=utf-8
Date 消息发送的日期和时间 Date: Wed, 21 Oct 2015 07:28:00 GMT
ETag 资源的版本标识符 ETag: "686897696a7c876b7e"
Expires 响应体的过期日期和时间 Expires: Wed, 21 Oct 2015 07:28:00 GMT
Last-Modified 资源的最后修改日期和时间 Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
Location 用于重定向,指明应该访问的URL Location: https://www.example.com/new-page
Server 包含处理请求的源头服务器所用到的软件相关信息 Server: Apache/2.4.41 (Unix)
Set-Cookie 由服务器端向客户端发送cookie Set-Cookie: sessionId=abc123; Path=/; Secure; HttpOnly
Strict-Transport-Security 告知浏览器只能通过HTTPS访问当前资源 Strict-Transport-Security: max-age=31536000
Transfer-Encoding 规定了传输消息体时采用的编码方式 Transfer-Encoding: chunked
Vary 告诉缓存服务器使用哪些请求头来决定是否可以直接使用已缓存的响应 Vary: Accept-Encoding, User-Agent
WWW-Authenticate 定义了使用何种验证方式去获取对资源的连接 WWW-Authenticate: Basic realm="Access to staging site"
X-Content-Type-Options 防止浏览器MIME类型嗅探 X-Content-Type-Options: nosniff
X-Frame-Options 控制页面是否可以在frame或iframe中显示 X-Frame-Options: DENY
X-XSS-Protection 启用跨站脚本过滤 X-XSS-Protection: 1; mode=block

通用头 (General Headers)

Header名称 说明 示例
Cache-Control 控制缓存行为 Cache-Control: no-cache, no-store, must-revalidate
Connection 控制网络连接 Connection: keep-alive
Date 消息产生的日期和时间 Date: Wed, 21 Oct 2015 07:28:00 GMT
Pragma 用于指定缓存行为(HTTP/1.0兼容) Pragma: no-cache
Trailer 允许发送方在分块发送的消息后面添加额外的元信息 Trailer: Expires
Transfer-Encoding 规定了传输消息体时采用的编码方式 Transfer-Encoding: chunked
Upgrade 要求服务器升级到另外一个协议 Upgrade: websocket
Via 显示代理服务器的相关信息 Via: 1.1 proxy.example.com (nginx/1.16.1)
Warning 告知可能影响到消息内容的问题 Warning: 199 Miscellaneous warning

实体头 (Entity Headers)

Header名称 说明 示例
Allow 对于特定资源有效的请求方法 Allow: GET, HEAD, PUT
Content-Encoding 实体消息体的编码方式 Content-Encoding: gzip
Content-Language 实体消息体的语言 Content-Language: zh-CN, en-US
Content-Length 实体消息体的长度 Content-Length: 1024
Content-Location 实体的位置 Content-Location: /documents/foo.html
Content-MD5 实体消息体的MD5校验值 Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ==
Content-Range 实体消息体在完整消息体中的位置 Content-Range: bytes 200-1023/1024
Content-Type 实体消息体的媒体类型 Content-Type: text/html; charset=utf-8
Expires 实体消息体的过期日期和时间 Expires: Wed, 21 Oct 2015 07:28:00 GMT
Last-Modified 实体消息体的最后修改日期和时间 Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT