how to make a curl POST request without displaying the response body, but keep the response header?

scones asked:

Hello friendly people of serverfault,

As stated above, i am looking for a way to hide the body, as it is just noise during testing.
I’d normally use -I, but that forces a HEAD request, which collides with POST.

Is there a way to do that with basic curl, or do i need to cut off parts with other tools?

maybe someone here knows more 🙂

thank you,
best regards,

My answer:

You can use -D to direct the output of the response headers, and -o to direct the output of the response body.

Here, we will output the headers to stdout, and the body to /dev/null.

$ curl --no-progress-meter -D - -o /dev/null
HTTP/2 200 
cache-control: private
content-type: text/html; charset=utf-8
server: Microsoft-IIS/10.0
strict-transport-security: max-age=2592000
x-route-name: Home/Index
x-frame-options: SAMEORIGIN
x-sql-count: 1
x-sql-duration-ms: 4
x-flags: AA
x-aspnet-duration-ms: 9
x-request-guid: a53259f4-9093-435c-96ec-d6077a93bd1d
x-is-crawler: 1
x-providence-cookie: 535994ba-b892-e116-4bf7-46d968d6adb3
x-page-view: 1
accept-ranges: bytes
date: Fri, 17 Jul 2020 13:52:25 GMT
via: 1.1 varnish
x-served-by: cache-yul8924-YUL
x-cache: MISS
x-cache-hits: 0
x-timer: S1594993946.828710,VS0,VE19
vary: Fastly-SSL
x-dns-prefetch-control: off
set-cookie: prov=535994ba-b892-e116-4bf7-46d968d6adb3;; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.