GET request examples with my most frequently used command-line options.
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:
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
--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
curl -L --max-redirs 60 http://blog.marcnuri.com
To save the output of the response you can either use the
-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
--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
--output command-line option:
curl -o result.html https://blog.marcnuri.com
You can use the
--head command-line option to instruct cURL to only retrieve the response headers (perform a
HEAD HTTP request):
curl -I https://blog.marcnuri.com
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.