HTTP 報文 = Message Header(消息頭) + Message Body(消息體)。Header 先行,包含請求頭、響應頭、通用頭、實體頭四類。
Accepttext/html, application/json;q=0.9Accept-Charsetutf-8, gbk;q=0.7Accept-Encodinggzip, deflate, brAccept-Languagezh-CN, zh;q=0.9, en;q=0.8Accept-Rangesbytes 支持斷點續傳,none 不支持Rangebytes=0-1023Content-Rangebytes 0-1023/2048If-RangeCache-Controlno-cache(驗證後用)、no-store(不緩存)、max-age=秒、public/private、must-revalidateExpiresWed, 21 Oct 2025 07:28:00 GMTETagIf-None-Match 驗證Last-ModifiedIf-Modified-SinceAgeVaryAccept-EncodingConnectionkeep-alive 持久連接,close 關閉Keep-Alivetimeout=5, max=100Transfer-Encodingchunked 分塊傳輸,HTTP/1.1 預設UpgradeAuthorizationBasic base64(user:pass)、Bearer tokenWWW-AuthenticateProxy-Authenticate / Proxy-AuthorizationContent-Typeapplication/json; charset=utf-8Content-LengthContent-EncodinggzipContent-LanguageContent-LocationHostapi.example.com:443(HTTP/1.1 必須)User-AgentRefererLocationServernginx/1.24.0Pragmano-cache 兼容 HTTP/1.0Via# 請求頭
GET /api/users HTTP/1.1
Host: api.example.com
User-Agent: Mozilla/5.0 ...
Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
If-None-Match: "abc123"
Connection: keep-alive
# 響應頭
HTTP/1.1 200 OK
Date: Mon, 23 Dec 2024 10:00:00 GMT
Server: nginx/1.24.0
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Content-Length: 1234
ETag: "abc123"
Cache-Control: max-age=300, must-revalidate
Vary: Accept-Encoding
Connection: keep-alive