Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo curl request header & body without sending it?

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?

like image 695
ma11hew28 Avatar asked May 30 '11 19:05

ma11hew28


People also ask

How do you get the header in curl request?

We can use curl -v or curl -verbose to display the request headers and response headers in the cURL command. The > lines are request headers . The < lines are response headers .

What headers does curl send by default?

Curl by default adds headers such as Content-type and User-agent .

How do I create a custom header in curl?

To add a custom header to Curl, you need to pass the -H "header: value" command line parameter to the Curl request. In this Curl Custom Headers example, we are sending a custom header to the ReqBin echo URL.


1 Answers

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 
like image 97
Anders Lindahl Avatar answered Sep 28 '22 21:09

Anders Lindahl