🕌
curlコマンドで「200」等のHTTPステータスコードを確認する方法とは?
はじめに
直近の業務でcurlコマンドでHTTPレスポンスステータスコードを確認する機会があり、使用頻度が高そうな方法のためアウトプットします。
環境
- Ubuntu 20.04.3 (WSL)
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$
方法
コマンド
curl -I <確認したいURL>
実行例
$ curl -I http://www.google.com/
HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-v76gg_QX442NBMQYzIr-Jw' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Date: Tue, 20 Jun 2023 11:14:13 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked
Expires: Tue, 20 Jun 2023 11:14:13 GMT
Cache-Control: private
Set-Cookie: 1P_JAR=2023-06-20-11; expires=Thu, 20-Jul-2023 11:14:13 GMT; path=/; domain=.google.com; Secure
Set-Cookie: AEC=AUEFqZfMaR_3cDRK03p-ZJFpxY5gxs5t6pVw6ptZ6yQLX_i-p83r_NMl5u8; expires=Sun, 17-Dec-2023 11:14:13 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
Set-Cookie: NID=511=aeV6kF6j96zR3exRCPCdAwjeMQZTJGgLcumRavu0KMZf87G6fSXZhmjKzlninldMiMkHJL00-HikuEdh43zT5BCRLFvCN7wiqYbRkhWWlcSGvaWAXgVxRrWjtKJctHlWJsy-BgcnWaNTT1Mhk7EnwUHAHf1e9opDx1fXdcNeKOs; expires=Wed, 20-Dec-2023 11:14:13 GMT; path=/; domain=.google.com; HttpOnly
$
参考情報
Discussion