3

Calling -v/--verbose on curl(1) will show me the HTTP headers of a request & response (and also tell me if curl is following a redirect). But if the server is over HTTPS/SSL/TLS, then it will also give me several lines about the TLS/SSL connection. I care about the HTTP headers, not the SSL details.

Is it possible to get curl to show me the HTTP headers, and not the SSL connection details?


$ curl --version curl 7.83.1 (x86_64-pc-linux-gnu) libcurl/7.83.1 OpenSSL/3.0.3 zlib/1.2.11 brotli/1.0.9 zstd/1.5.2 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.0) libssh2/1.10.0 nghttp2/1.47.0 librtmp/2.3 OpenLDAP/2.5.12 Release-Date: 2022-05-11 Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets zstd 

3 Answers 3

3

curl -D - https://uri/ will display the response's headers + body.

3

curl -I performs a HEAD requests and displays headers (there could be no body).

curl -i allows to use arbitrary request method, and displays both headers and the body.

From man curl:

 -I, --head (HTTP FTP FILE) Fetch the headers only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document. When used on an FTP or FILE file, curl displays the file size and last modification time only. -i, --include Include the HTTP response headers in the output. The HTTP response headers can include things like server name, cookies, date of the document, HTTP version and more... To view the request headers, consider the -v, --verbose option. See also -v, --verbose. 
1
curl -v https://example.com 2>&1 > /dev/null | grep -P '^[<>]' 

This hides also a bunch of other stuff like IPs, ports etc. but if you're interested only in the headers, it works.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Feb 27, 2024 at 19:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.