curl -sS -o /dev/null -w '%{http_code}\n' https://example.com
curl -sS -I https://example.com
curl -sS -D - -o /dev/null https://example.com
curl -sS -o /dev/null -w '%{http_code} %{time_total}\n' https://example.com
curl -sS -L -o /dev/null -w '%{http_code} %{url_effective}\n' http://example.com
curl -sS -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8080/health
curl -sS -H 'Host: api.example.com' http://10.0.0.10/health
curl -sS --resolve api.example.com:443:10.0.0.10 https://api.example.com/
curl -sS -k -o /dev/null -w '%{http_code}\n' https://example.com
curl -sS -X POST -H 'Content-Type: application/json' -d '{}' -w '%{http_code}\n' https://api.example.com/v1
| 目的 | 写法/命令 | 注意 |
|---|---|---|
| 继续请求 | 100 Continue |
中间响应,不是最终结果 |
| 协议升级 | 101 Switching Protocols |
WebSocket 等升级场景 |
| 请求成功 | 200 OK |
不代表业务逻辑成功 |
| 创建成功 | 201 Created |
常配合 Location |
| 成功无响应体 | 204 No Content |
不能携带 body |
| 永久重定向 | 301 Moved Permanently |
缓存行为需评估 |
| 临时重定向 | 302 Found |
客户端可能改为 GET |
| 缓存命中 | 304 Not Modified |
不能携带响应体 |
| 请求参数错误 | 400 Bad Request |
查客户端请求体与字段 |
| 未认证 | 401 Unauthorized |
缺凭证或 token 失效 |
| 已认证无权限 | 403 Forbidden |
查 ACL、RBAC、IP 限制 |
| 资源不存在 | 404 Not Found |
也可能是路由或代理路径错 |
| 请求被限流 | 429 Too Many Requests |
看 Retry-After 与配额 |
| 客户端断开 | 499 Client Closed Request |
Nginx 自定义,查上游耗时 |
| 上游响应非法 | 502 Bad Gateway |
上游崩溃、端口或协议错 |
| 服务不可用 | 503 Service Unavailable |
无健康后端、维护或限流 |
| 上游超时 | 504 Gateway Timeout |
上游慢或超时配置过短 |
curl -I 验证所有接口;正确:HEAD 与 GET 行为可能不同,必要时用 -D - -o /dev/null。-L 并用 %{url_effective} 确认最终地址。
小程序版
微信扫码,随时查命令