cURL Basics
Introduction to cURL
cURL (Client URL) is a powerful command-line tool and library for transferring data using various protocols. As a versatile network tool, cURL supports HTTP, HTTPS, FTP, SFTP, and many other network protocols, making it essential for web development and network operations.
Core Functionality
cURL enables developers and system administrators to:
- Transfer data between servers
- Test web services
- Download files
- Send HTTP/HTTPS requests
- Authenticate network connections
graph LR
A[Client] -->|cURL Request| B[Web Server]
B -->|Response| A
Basic cURL Command Structure
The fundamental syntax of cURL is straightforward:
curl [options] [URL]
Common cURL Options
Option |
Description |
Example |
-X |
Specify HTTP method |
curl -X GET |
-H |
Add custom headers |
curl -H "Content-Type: application/json" |
-d |
Send POST data |
curl -d "param1=value1" |
-o |
Save output to file |
curl -o output.html |
Practical Examples
Simple GET Request
curl
This command retrieves public information about the GitHub user "octocat" in JSON format.
Download a File
curl -O
Downloads the file and saves it with its original filename.
POST Request with JSON Data
curl -X POST \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"secret"}' \
Demonstrates sending JSON data in a POST request for authentication.
cURL's lightweight nature and extensive protocol support make it a critical tool for web development, network testing, and automated scripting across various Linux environments.