curl Command
The curl command transfers data from or to servers using various protocols including HTTP, HTTPS, FTP, and more. It's a powerful tool for downloading files, making API calls, and testing web services.
Syntax
Description
The curl command is a versatile tool for transferring data with servers. It supports numerous protocols and can be used for various tasks from simple file downloads to complex API interactions.
Key features:
- Supports HTTP, HTTPS, FTP, FTPS, and many other protocols
- Can send various types of HTTP requests (GET, POST, PUT, DELETE, etc.)
- Handles cookies, authentication, and headers
- Supports file uploads and downloads
- Can follow redirects and handle SSL certificates
Common Options
| Option | Description |
|---|---|
-o, --output |
Write output to file instead of stdout |
-O, --remote-name |
Save with remote filename |
-X, --request |
Specify request method (GET, POST, etc.) |
-H, --header |
Add custom header to request |
-d, --data |
Send data in POST request |
-u, --user |
Server user and password |
-L, --location |
Follow redirects |
-s, --silent |
Silent mode (no progress bar) |
-v, --verbose |
Verbose output |
Examples
Basic HTTP GET request
Fetches the content from the URL and displays it
Download file with original name
Downloads the file and saves it as 'file.zip'
Download file with custom name
Downloads the file and saves it as 'myfile.zip'
POST request with data
Sends a POST request with form data
POST request with JSON data
Sends a POST request with JSON data
Add custom headers
Includes custom headers in the request
Follow redirects
Follows HTTP redirects automatically
Basic authentication
Uses HTTP basic authentication
Upload file
Uploads a file using multipart form data
Save response headers
Saves response headers to a file