# ===== CodeLab: HTTP 协议基础 ===== # 来源: https://aoerliang.dpdns.org/articles/http-basics # 以下代码片段按文章出现顺序拼接, 共 5 段 # ----- 片段 1 (text) ----- https://user:pass@example.com:443/path/page?q=hello#section └─┬─┘ └──┬──┘ └──┬───┘ └─┬─┘ └──┬───┘ └──┬──┘ └───┬───┘ 协议 认证信息 主机名 端口 路径 查询参数 锚点 # ----- 片段 2 (http) ----- GET /index.html HTTP/1.1 Host: www.example.com User-Agent: curl/8.0 Accept: text/html Cookie: session=abc123 # ----- 片段 3 (http) ----- HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 1234 Set-Cookie: lang=zh-CN ... # ----- 片段 4 (bash) ----- # 查看响应头 curl -I https://example.com # 携带请求头 curl -H "Authorization: Bearer TOKEN" https://api.example.com/user # POST JSON 数据 curl -X POST https://api.example.com/users \ -H "Content-Type: application/json" \ -d '{"name": "Ada"}' # 跟随重定向并输出详细过程 curl -L -v https://example.com 2>&1 | head -30 # ----- 片段 5 (http) ----- # 响应头示例 Cache-Control: max-age=86400 # 一天内直接用缓存 ETag: "33a64df5" # 内容的指纹 Last-Modified: Wed, 21 Oct 2026 07:28:00 GMT # 浏览器下次请求会带上 If-None-Match: "33a64df5" If-Modified-Since: Wed, 21 Oct 2026 07:28:00 GMT # 服务器比对后没变化 → 304 Not Modified(不返回 body)