Curl is a fantastic tool for making web requests from the command line. As a developer, I find this tool particularly useful.
Retrieve Content at a URL
curl https://salferrarello.com/
Making a HEAD Call
Sometimes, we want to see the Header Values returned from a URL using the HEAD.
The HTTP HEAD method requests the headers that are returned if the specified resource would be requested with an HTTP GET method.
curl -I https://salferrarello.com/
Note If you want to see the headers returned for a different call (e.g. POST) see “Display response Headers” below.
Passing Data
Passing Data with Get
With a GET call, we add data as part of the URL.
e.g. https://salferrarello.com/?s=curl
Passing data with Post
We can also pass the data using the POST method instead of the GET method, by adding -d
to indicate we are passing data we automatically get a POST (not a GET) call
curl https://salferrarello.com/ -d p=5960
Passing JSON Data
When passing JSON data, we need to inform the web server that we are giving it JSON data by including the appropriate header with -H "Content-Type: application/json"
curl https://salferrarello.com/ -H "Content-Type: application/json" --data '{"username":"xyz","password":"xyz"}'
Display Response Headers
You can dump the response headers to a file for any call using the -D
parameter, e.g. curl https://salferrarello.com -D responseHeaders.txt
Display Response Headers on Screen
We can also display the response headers as part of our output (before the content) by using -D -
curl https://salferrarello.com -D -
or
curl POST https://salferrarello.com/ -d p=5960 -D –
Leave a Reply