Skip to content

HTTP 请求头

一句话解释

HTTP 请求头是 键-值 pair 那个发送 metadata 关于请求 or 响应, 例如内容类型, 缓存, and 认证.

用大白话说

HTTP headers are metadata sent with every HTTP request and response. They provide information about the data being sent — its type, size, encoding, caching rules, authentication tokens, and more. Headers are key-value pairs separated by a colon.

Common request headers include: Host (the domain), 用户-Agent (browser info), 接受 (expected content type), 授权 (credentials), and 内容-类型 (body format for POST/PUT). Common response headers include: 内容-类型, 内容-长度, 缓存-Control, 设置-Cookie, and 位置 (for redirects).

Headers are essential for proper HTTP communication. In JavaScript, you can set request headers with the Fetch API and read response headers with 响应.请求头.获取('name'). Some headers are restricted for security reasons and cannot be set from JavaScript.

示例

http
GET /api/users HTTP/1.1
Host: api.example.com
Accept: application/json
Authorization: Bearer token123
User-Agent: Mozilla/5.0

---

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=3600

请求请求头 (Host, 接受, 授权, 用户-Agent) and 响应请求头 (内容-类型, 缓存-Control).

相关术语

相关资源

相关课程

  • HTTP

    HTTP protocol and 请求头.

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表