用 curl 查看 HTTP 响应头
向任意 URL 发送 HEAD 请求,打印状态行、服务器类型、内容类型、缓存和重定向等响应头。
执行 curl -I https://example.com,即可查看 HTTP 状态码和所有响应头。
01命令
命令
$ curl -I https://example.com02作用说明
curl -I 发送的是真正的 HEAD 请求,因此可以看到 Content-Type、Cache-Control、Location 等头部而不下载正文。有些服务器对 HEAD 和 GET 的响应不同;要查看真实 GET 请求的头,用 curl -s -o /dev/null -D - URL(丢弃正文,把头输出到终端)。加 -L 可跟随重定向并追踪整个跳转链(每一跳的头按顺序显示),排查 TLS 细节加 -v。测试 API 或缓存行为时,可用 -H 'Header: value' 添加请求头。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- curl(1) — transfer a URL依据: The curl man page documents -I / --head as fetching the HTTP headers only, using the HEAD method.
- curl man page — official documentation依据: The official curl documentation describes --head as fetching headers only and -o / --output for discarding or redirecting the body.
最后验证: 2026-09-17 · 分类: 网络