75

I want to get the headers only from a curl request

curl -I www.google.com

All grand. Now I want to do that but to pass in post data too:

curl -I -d'test=test' www.google.com

But all I get is:

Warning: You can only select one HTTP request!

Anyone have any idea how to do this or am I doing something stupid?

J.D. Fitz.Gerald
  • 2,977
  • 2
  • 19
  • 17

2 Answers2

124

The -I option tells curl to do a HEAD request while the -d'test=test' option tells curl to do a POST, so you're telling curl to do two different request types.

curl -s -d'test=test' -D- -o/dev/null www.google.com 

or, on Windows:

curl -s -d'test=test' -D- -onul: www.google.com 

That is the neatest way to do this as far as I can find. The options are:

  • -D- Dump the header to the file listed, or stdout when - is passed, like this.
  • -o/dev/null Send the body to the file listed. Here, we discard the body so we only see the headers.
  • -s Silent (no progress bar)
Eddie
  • 53,828
  • 22
  • 125
  • 145
J.D. Fitz.Gerald
  • 2,977
  • 2
  • 19
  • 17
  • 15
    An explanation of what the flags mean would be helpful – Madbreaks Apr 04 '12 at 17:49
  • 8
    **-s**: silent (no progress-bar) **-d **: performs a POST with the given query-string  **-D **: dump-header to file (stdout when - is passed) **-o **: output response to file The manual cites all these flags anyway. – raphael Aug 20 '12 at 18:24
  • If someone wants to run this on Windows just replace `-o/dev/null` with `-o nul` (tested in Windows XP). – Jan Święcki Dec 31 '12 at 01:25
30

-d means you are sending form data, via the POST method. -I means you are just peeking at the metadata via HEAD.

I'd suggest either

  • Download to /dev/null and write the headers via the -D headerfile to the file headerfile
  • Use -i to include the headers in the answers and skip everything from the first empty line.
phihag
  • 278,196
  • 72
  • 453
  • 469