cURL: GET request examples
cURL HTTP GET
request examples with my most frequently used command-line options.
HTTP GET
request
The most basic command you can execute with cURL is an HTTP GET
request. The following command will perform the request and output the response body:
curl https://blog.marcnuri.com
HTTP GET
request and follow redirects
Many times when we perform a GET
HTTP request, the server responds with a 3xx
redirect HTTP status code. Most times, we're not interested on this response, but on the response of the final redirected URL.
To tell cURL to follow redirects we can use the -L
, --location
command-line option:
curl -L http://blog.marcnuri.com
By default, cURL will follow a maximum of 50 redirects. If this is not enough, the value can be overridden by using the --max-redirs
option:
curl -L --max-redirs 60 http://blog.marcnuri.com
HTTP GET
request and save output to file
To save the output of the response you can either use the -O
or -o
command-line options.
In case you want to save the command output to a file with the same name as the remote file-name, you can use the -O
, --remote-name
command-line option (this requires that the request is performed to a remote file):
curl -O https://blog.marcnuri.com/index.html
If you want to write the output to a specific file you can use the -o
,--output
command-line option:
curl -o result.html https://blog.marcnuri.com
HTTP HEAD
request, retrieving only the response headers
You can use the -I
, --head
command-line option to instruct cURL to only retrieve the response headers (perform a HEAD
HTTP request):
curl -I https://blog.marcnuri.com
Summary
These are some of the common cURL GET
HTTP request examples I use on a daily basis. I hope they may come in useful for you too.