We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
curl -I 可以返回响应头,当然也就包含了响应状态码。
curl -I
如果想只要状态码,那么可以这样做:
$ curl -sS -w "%{http_code}" -o /dev/null https://www.baidu.com 200
如果请求失败,那么返回 000
000
否
$ cat main.go && go run main.go& package main import ( "log" "net/http" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { w.WriteHeader(500) }) log.Println("listen and serving...") _ = http.ListenAndServe(":8080", nil) } $ curl locahost:8080 $ echo $? 0
如果想要 shell 返回错误码,可以加上 -f 参数,非 200 会返回 shell 22 error code
-f
The text was updated successfully, but these errors were encountered:
islishude
No branches or pull requests
curl -I
可以返回响应头,当然也就包含了响应状态码。如果想只要状态码,那么可以这样做:
$ curl -sS -w "%{http_code}" -o /dev/null https://www.baidu.com 200
如果请求失败,那么返回
000
否
如果想要 shell 返回错误码,可以加上
-f
参数,非 200 会返回 shell 22 error codeThe text was updated successfully, but these errors were encountered: