0

Currently I am experimenting with curl flags, looking how to get only the response headers, follow the redirection if any, encryption and authentication used and the round trip time.

What flag should I use to hide/disable the HTML body in the output?

2

How to make curl disable html output

Use the -s flag (for silent operation) and redirect stout (>) to (eg) /dev/null (or, if you're on Windows, simply NUL)

This, inc combination with -D <file> (aka --dump-header) may give you the output you are looking for.

The curl manpage has more information on the command-line options which may be helpful.

Example

$ curl -s https://superuser.com -D su.txt > /dev/null
$ less -FX su.txt
HTTP/2 200 
date: Sun, 25 Feb 2018 17:24:30 GMT
content-type: text/html; charset=utf-8
x-frame-options: SAMEORIGIN
x-request-guid: e147da19-7cc9-42cd-8706-4204fd64d4a9
strict-transport-security: max-age=15552000
content-security-policy-report-only: default-src https: wss: data: blob: 'unsafe-eval' 'unsafe-inline'; report-uri https://stackoverflow.report-uri.io/r/default/csp/reportOnly
accept-ranges: bytes
via: 1.1 varnish
x-served-by: cache-lcy19224-LCY
x-cache: MISS
x-cache-hits: 0
x-timer: S1519579470.439587,VS0,VE88
vary: Fastly-SSL
x-dns-prefetch-control: off
set-cookie: prov=d007391b-afc2-4717-282a-287f18827242; domain=.superuser.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
cache-control: private
content-length: 101543
  • What about a Windows environment that uses git bash to curl ? – user876358 Feb 25 '18 at 17:42
  • Windows' equivalent to /dev/null is simply NUL; I assume git bash will respect that but cannot test at the minute. I have updated my answer to include that. – bertieb Feb 25 '18 at 17:48
  • 1
    In addition, some quick searches indicates that git bash implements /dev/null, so /dev/null may work in that case! – bertieb Feb 25 '18 at 17:50
1

You can discard the body while still keeping the headers by telling curl to dump them on stdout:

$ curl -D/dev/stdout -o/dev/null -s https://superuser.com
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
X-Frame-Options: SAMEORIGIN
X-Request-Guid: a599d44b-705c-4615-a8d8-80c7614bd64f
...
  • -D/dev/stdout: dump the headers on standard output
  • -o/dev/null: discard the body
  • -s: disable the progress meter
  • 1
    More people should document what the command options mean in their answers like you have. – jrahhali Jan 26 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy