Curl is one of the best tools for debugging network requests and testing APIs without user interaction. Curl can be used as a standalone console application or compiled into other programs as a dynamic library (libcurl). Curl has built-in support for SSL, user authentication, certificate validation, and HTTP cookies. You can use Curl to download or upload files, submit web forms, send requests to API endpoints, and simulate user actions without using a web browser.
Curl is a command-line tool that allows you to transfer data over the network using over 25+ protocols, including HTTP, HTTPS, FTP, and works on Linux, macOS, and Windows platforms. Curl is free and open-source, has an excellent distribution license agreement, can be used in commercial or closed source applications, and is widely used in many popular applications and browsers.
How to use Curl on Windows?
To use Curl on Windows, follow these steps:
Download Windows Installer from Curl official website (64-bit recommended).
Open the Curl.zip folder and unzip it into the desired local folder on your computer, for example, C:\Curl.
Add the Curl folder (C:\Curl\bin) to your Windows PATH environment variable to invoke the Curl command from any other folder.
Enter curl --version on the command line to make sure you can Curl commands. If Curl is installed correctly, you will see something like this:
Curl comes bundled with macOS. You can update Curl to the latest version by installing macOS Homebrew Software Package Manager. Once you've installed the Homebrew Package Manager on macOS, open a terminal and type:
Install Curl on macOS
brew install curl
If Curl is installed correctly, you will see something like this when you type curl --version:
If this option is enabled, then all data specified in the -d option will be transferred using the GET method
Send headers to the server
Receive only the HTTP header, and ignore the entire page content
Accept and process redirects
Output the content of the page to a file
Save the content to a file with the name of the page or file on the server
Maximum verbose output
How to download files using Curl?
Curl can download files from a remote location. Curl can do this with the command line options -O (save the file with the same name as the remote one) or -o (allow a different filename or location).
Curl using -O command-line
curl -O [URL]
Curl using -o command-line
curl -o [file name] [URL]
How to send POST requests data using Curl?
Using the POST method, you can send files and any data. This method also sends data of various forms. Use the -d option to send such a request.
Curl using -d command-line
curl -d "key1=value1&key2=value2" [URL]
How to get HTTP headers using Curl?
An HTTP request invariably contains a header. The HTTP headers send additional information about the remote web server along with the actual request. With the tools in the browser, you can see the header information and check it with the Curl command.
Curl using -I command-line
curl -I [URL]
How to send cookies using Curl?
If you have HTTP cookies in the file, you can send them to the site, and you can also use the utility to check which cookies are loaded by the URL.
Curl using --cookie command-line
curl --cookie "Name=Value" [URL]
How do I get HTTP Authentication using Curl?
If the server requires authentication of one of the common types, for example, HTTP or FTP, then Curl can handle this task. To specify authentication data, specify them separated by colons in the -u option:
Curl using -u command-line
curl -u [Username:Password] -T [ftp://URL]
How to upload files for FTP connections?
Curl supports FTP protocol. You can use it to download files from a remote server, and you can omit the username and password for anonymous FTP connections.
Curl using FTP
curl -u [Username:Password] -O [ftp://URL]
How to transfer files to Curl?
In addition to uploading files, the utility allows you to perform other actions, for example, sending files to an FTP server. There is a -T option for this:
Curl using -T command-line
curl -T page.html [URL]
How do I use a proxy to connect to Curl?
To use a proxy server to download files, you need to specify the proxy server address in the -x option:
To set a timeout for a Curl command, you can use the --connect-timeout parameter to set the maximum time in seconds that you allow Curl to connect to the server, or the --max-time (or -m) parameter for the total time in seconds that you authorize the whole operation.
Curl –connect-timeout syntax
curl -m [SECONDS] [URL]
Curl -max-time syntax
curl --connection-timeout [SECONDS] [URL]
How to limit download speed in Curl?
When downloading or uploading data using Curl, you have no way of knowing how large the output will be. You can limit your download speed to make sure Curl is not restricting your bandwidth. The command below will cap the download speed to 100K:
Curl using --limit-rate command-line
curl --limit-rate 100k -O [URL]
Curl is a powerful yet easy-to-use tool for automating day-to-day tasks and testing APIs. Curl has over 380 flags that you can use to customize almost any aspect of Curl. Libcurl is a free open source cross-platform library with an extensive API that can be used in many popular programming languages, supports over 25+ protocols. And works on all modern platforms.