Echo curl request header & body without sending it?
Solution 1
Let me second the suggestion to use 'nc' (netcat) to get to see all the details without sending anything offsite to anywhere.
But you can also get all the details for any curl command line request by using the --trace or --trace-ascii commands that can dump all incoming and outgoing data and requests for inspection.
These options have the additional benefit in comparison to 'nc' that they can show the protocol details even for HTTPS operations and with "real" command lines etc.
Solution 2
A HTTP request is constructed with a request line, headers and a body.
curl does not seem to have a flag to do a "dry-run". Depending on your needs, you might be able to see what you want using netcat as a proxy:
$ nc -l localhost 8000 &
[1] 3150
$ curl --proxy localhost:8000 --silent --max-time 1 http://www.stackoverflow.com
GET http://www.stackoverflow.com HTTP/1.1
User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
Host: www.stackoverflow.com
Accept: */*
Proxy-Connection: Keep-Alive
[1]+ Done nc -l localhost 8000
ma11hew28
Updated on July 09, 2022Comments
-
ma11hew28 almost 2 years
With the curl command line tool, is it possible to
echo
, print, or view the request, and not send it? Sort of like a-n
option? I would like to see the request header & body, and anything else that's included. Is there anything else that's sent besides header & body? -
Ciro Santilli OurBigBook.com about 10 years
--trace -
for stdout. -
Randall over 7 yearsHow did you get the netcat to terminate cleanly (
[1]+ Done
)? In my test, I'm finding I need toCtrl-C
out of it, thenfg
it, and thenCtrl-D
. It works, but seems a clunky way to exit the netcat. -
Randall over 7 yearsAh - it looks like the key was the
--max-time 1
flag, to time it out, with the--silent
to suppress the time out message. I omitted those both initially. -
Edoardo about 7 years...of course this will not work with HTTPS, it shows only
CONNECT www.stackoverflow.com:443 HTTP/1.1
and Proxy-Connection: Keep-Alive