我可以让 curl 只打印响应代码吗?

use*_*669 5 curl http

我读了https://superuser.com/questions/272265/getting-curl-to-output-http-status-code。它提到

curl -i 
Run Code Online (Sandbox Code Playgroud)

将打印 HTTP 响应代码。是否可以让 curl 打印HTTP 响应代码?是否有一种通用方法可以获取任何类型的请求(如 GET/POST/etc)的 HTTP 状态代码?

我在 Mac OS High Sierra 上使用 curl 7.54.0。

谢谢阅读。

use*_*669 9

这对我有用:

$  curl -s -w "%{http_code}\n" http://google.com/ -o /dev/null
Run Code Online (Sandbox Code Playgroud)

  • 如果您更喜欢手写参数名称:`-s` = `--silent`、`-w` = `--write-out`、`-o` = `--output` (2认同)