LoginSignup
58
41

More than 1 year has passed since last update.

cURLコマンドでレスポンスヘッダのみを取得する --head

Last updated at Posted at 2017-04-23

--head でできます!

元の記事を書い際には見つけられていなかったのですが、 --head でレスポンスヘッダーのみを取得することができます!!!

$ curl --head http://example.com

HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Age: 431277
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Tue, 29 Jun 2021 15:49:43 GMT
Etag: "3147526947"
Expires: Tue, 06 Jul 2021 15:49:43 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (oxr/8314)
X-Cache: HIT
Content-Length: 648

バラバラにオプションを指定する

-D -で標準出力にヘッダを出力。(--dump-header)
-sで進捗などを表示しないサイレントモード。(--silent)
-o /dev/nullでbodyを/dev/nullに捨てる。 (--output)

$ curl -D - -s  -o /dev/null http://example.com


HTTP/1.1 200 OK
Cache-Control: max-age=604800
Content-Type: text/html
Date: Sun, 23 Apr 2017 01:45:02 GMT
Etag: "359670651+ident"
Expires: Sun, 30 Apr 2017 01:45:02 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (cpm/F9FC)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1270

エイリアス化しておくと便利そう。

~/.bashrc
alias curl_header='curl -D - -s -o /dev/null'
58
41
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
58
41