cURL Examples

cURL is tool that can be used to easily transfer data between servers. It supports a variety of protocols including HTTP, FTP, TELNET and many more. We will show several examples of cURL that can be used through a terminal. In this article about the top 5 cURL examples for beginners, you can learn how to – view the HTTP response of a website, download a file, transfer a file, post data to a server or api or view the headers of a response.

Using cURL to view the HTTP response of a website

This will output the response of the web server hosting the domain to your console

curl domain.com

Sometimes this will provide an output informing you that the resource has been moved to a different address, you can follow the redirect using -L

curl -L domain.com

If you’re making a request to a resource that has HTTP Authentication turned on you can Authenticate using

cPanel Hosting from WebhostFace
curl -u user:password domain.com

Downloading a file using cURL

This will download a file. The difference is when to use -o or -O with lower or capital letter. Lowercase will save a file of your choice whether -O will save the file as it was called on the server.

curl -o myFile.zip http://www.domain.com/downloads/file.zip
curl -O http://www.domain.com/downloads/file.zip

You can also transfer files through FTP using cURL

This will work the same way as transferring a file through an FTP client like FileZilla

curl -u ftpUser:password -T fileToDownloadViaFtp.tar.gz ftp://hostname.ftpserver.com

Using cURL to POST Data to a Server or API

Although not very handy you can use cURL to make API calls

curl -d '{"JSONKey":"JSONValue"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data

Using cURL to view the Headers of a Response

curl -L domain.com
curl --head domain.com

Start your web hosting project now with a greatly discounted price of all our shared hosting plans! Grow your project on an SSD VPS hosting or Dedicated Server!