13. Curl Fundamentals
Overview¶
curl (Client URL) is a command-line tool used to transfer data to or from a server using various protocols. It is widely used for:
-
Testing APIs
-
Downloading files
-
Debugging network issues
-
Web requests in automation and cybersecurity
Supported Protocols¶
curl supports multiple protocols, including:
-
HTTP
-
HTTPS
-
FTP
-
SFTP
-
Telnet
Basic Syntax¶
Fetch Website Content¶
Explanation
-
Sends a GET request
-
Displays the HTML/content of the webpage in the terminal
Save Output to File¶
Explanation
-o→ save output with custom file name and path
Download Files¶
Save with Custom Name¶
Save with Original Name¶
Explanation
-O→ saves file using the name from URL
Handle Redirects¶
Explanation
-
-L→ follows redirects automatically -
Required when URLs redirect to another location
View Response Headers¶
Explanation
-
-I→ fetch only HTTP headers -
Useful for checking server response
Example Output¶
Verbose Mode (Debugging)¶
Explanation
-
Shows detailed request/response info
-
Includes:
-
Request headers
-
Response headers
-
TLS handshake
-
Connection details
-
Send POST Request (Data Submission)¶
Example: Login Request¶
Explanation
-
Sends POST request with parameters
-
Used in API testing and form submission
Common curl Options¶
| Option | Description |
|---|---|
-o |
Save output with custom name |
-O |
Save with original filename |
-L |
Follow redirects |
-I |
Show response headers |
-v |
Verbose/debug mode |
--data |
Send POST data |
Practical Examples¶
Download a File¶
Save Webpage Content¶
Check Server Response¶
Debug Connection¶
Send API Request¶
Important Notes¶
-
Always use
-Lwhen dealing with redirects -
Use
-vfor troubleshooting network issues -
Avoid sending sensitive data over HTTP (use HTTPS)
-
Combine curl with other tools for automation
Summary Table¶
| Command | Purpose |
|---|---|
curl URL |
Fetch webpage content |
curl -o file |
Save output |
curl -O URL |
Download file |
curl -L URL |
Follow redirects |
curl -I URL |
Show headers |
curl -v URL |
Debug request |
curl --data |
Send POST request |
Conclusion¶
curl is a powerful and versatile tool for:
-
Web interaction
-
API testing
-
File transfer
-
Network debugging
Mastering curl is essential for developers, system administrators, and cybersecurity professionals working in Linux environments.