A logo showing the text blog.marcnuri.com
Español
Home»Tools»cURL: GET request examples

Recent Posts

  • Fabric8 Kubernetes Client 6.4.0 is now available!
  • I bought an iPad
  • Three years at Red Hat
  • Fabric8 Kubernetes Client 6.3.1 is now available!
  • Eclipse JKube 1.10 is now available!

Categories

  • Front-end
  • Java
  • JavaScript
  • Legacy
  • Operations
  • Personal
  • Pet projects
  • Tools

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • December 2019
  • October 2019
  • September 2019
  • July 2019
  • March 2019
  • November 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • December 2017
  • July 2017
  • December 2015
  • November 2015
  • November 2008
  • November 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007

cURL: GET request examples

2021-08-01 in Tools tagged curl / HTTP / Quickie by Marc Nuri | Last updated: 2021-08-01
Versión en Español

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.

References

  • The book: Everything curl
  • cURL Man Page
Twitter iconFacebook iconLinkedIn iconPinterest iconEmail icon

Post navigation

← How to show whitespace in IntelliJ IDEAEclipse JKube 1.4.0 is now available! →
© 2007 - 2023 Marc Nuri