curl -IXGET http://example.com/file.txt
$ curl -IXGET http://www.woolie.co.uk HTTP/1.1 200 OK Content-Type: text/html; charset=UTF-8 Content-Length: 1662 Cache-Control: max-age=3600 Content-Encoding: gzip ETag: "491e3f837bca4470f09871ab186a93a7"
-IXGET argument stumped me for a while, mainly because my brain was
-IXGET as one argument. It’s actually layering 2 arguments:
-I- tells cURL to make a HEAD request. Delving through the source code shows adding this argument does nothing more than set the following CURLOPTs:
-X- allows you to dumbly overwrite the HTTP request method sent with the request, in our case replacing HEAD that
-Itriggered with GET.
If you feel like confusing a server, cURL doesn’t sanity check
-X and you can overwrite it with whatever you fancy:
$ curl http://www.google.co.uk/ -XDONKEY -v -s -o /dev/null > DONKEY / HTTP/1.1 > User-Agent: curl/7.37.1 > Host: www.google.co.uk > Accept: */* > < HTTP/1.1 405 Method Not Allowed < Content-Type: text/html; charset=UTF-8 < Content-Length: 1455 < Server: GFE/2.0
For years I’d always used the following cURL arguments to achieve the same as
curl -s -o /dev/null -D - http://example.com/file.txt
This asks to send all HTTP response body to
/dev/null but to dump the
response headers to