How to hide the html body when using curl

curlhttps

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?

Best Answer

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
Related Question