Accept-Language: zh-cn,zh;q=0.5 Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 (compatible; example.com) Host: example.com Connection: Keep-Alive
Accept-Language: zh-cn,zh;q=0.5
zh-cn 默認 q=1,優先級更高服務端可據此返回本地化內容,如多語言站點的語言協商。
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
現代 Web 應統一輸出 UTF-8,忽略此頭或作為兼容參考。
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
| 類型 | 含義 | q值 |
|---|---|---|
| text/html | HTML 文檔 | 1.0 |
| application/xhtml+xml | XHTML 文檔 | 1.0 |
| application/xml | XML 文檔 | 0.9 |
| */* | 任意類型 | 0.8 |
MIME 結構:type/subtype。text/* 文本類,application/* 應用/二進制類。服務端應根據此頭決定響應格式(HTML vs JSON vs XML)。
Accept-Encoding: gzip, deflate
服務端檢測此頭決定是否壓縮響應體,Content-Encoding: gzip 回應。
User-Agent: Mozilla/5.0 (compatible; example.com)
用途:統計分析、兼容性適配、爬蟲識別、設備類型判斷(移動端/PC)。不可信任,易偽造。
Host: example.com
HTTP/1.1 必須頭。虛擬主機環境下,服務端據此路由到正確站點。包含端口時格式:Host: example.com:8080。
Connection: Keep-Alive
| 頭字段 | 作用 | 典型值 |
|---|---|---|
| Accept | 可接受媒體類型 | text/html, application/json |
| Accept-Charset | 可接受字符集 | utf-8, iso-8859-1 |
| Accept-Encoding | 可接受壓縮編碼 | gzip, deflate, br |
| Accept-Language | 可接受自然語言 | zh-CN, zh;q=0.9, en;q=0.8 |
| Authorization | 認證憑據 | Bearer <token>, Basic <base64> |
| Cache-Control | 緩存控制指令 | no-cache, max-age=3600 |
| Cookie | 攜帶 Cookie | session_id=abc; pref=dark |
| If-Modified-Since | 條件請求:修改時間 | Wed, 21 Oct 2015 07:28:00 GMT |
| If-None-Match | 條件請求:ETag | "abc123" |
| Referer | 來源頁面 URL | https://google.com/search?q=php |
| User-Agent | 客戶端標識 | Mozilla/5.0... |
| X-Forwarded-For | 代理鏈原始客戶端 IP | 203.0.113.195 |
| X-Requested-With | AJAX 請求標識 | XMLHttpRequest |
| 頭字段 | 作用 | 典型值 |
|---|---|---|
| Location | 重定向目標 | /login (配合 302) |
| Content-Encoding | 響應體壓縮格式 | gzip |
| Content-Length | 響應體字節長度 | 1234 |
| Content-Type | 響應媒體類型 | text/html; charset=utf-8 |
| Last-Modified | 資源最後修改時間 | Wed, 21 Oct 2015 07:28:00 GMT |
| ETag | 資源實體標籤 | "abc123" / W/"weak" |
| Set-Cookie | 設置 Cookie | sid=abc; Path=/; HttpOnly; Secure |
| Cache-Control | 緩存策略 | public, max-age=3600 |
| Expires | 過期時間(HTTP/1.0) | Wed, 21 Oct 2015 07:28:00 GMT |
| Refresh | 定時刷新/重定向 | 5; url=/dashboard |
| Content-Disposition | 下載文件名建議 | attachment; filename="report.pdf" |
| Strict-Transport-Security | HSTS 強制 HTTPS | max-age=31536000 |
| Access-Control-Allow-Origin | CORS 允許源 | https://app.example.com |
Expires: 0 Cache-Control: no-cache, no-store, must-revalidate Pragma: no-cache
兼容 HTTP/1.0 (Pragma/Expires) 與 HTTP/1.1 (Cache-Control),確保絕不緩存敏感頁面(登錄、支付、個人信息)。
HTTP 頭字段是客戶端與服務端協商的語言。精通請求/響應頭的語義、優先級、交互邏輯,是構建高性能、安全、可觀測 Web 服務的基礎能力。建議配合瀏覽器 DevTools Network 面板、curl -v、Wireshark 實戰觀察分析。