curl
Overview
The curl
command is a tool for transferring data using various protocols. It supports HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP, and FILE.
Syntax
curl [options] [URL...]
Common Options
Option | Description |
---|---|
-o file |
Output to file |
-O |
Remote filename |
-L |
Follow redirects |
-i |
Include headers |
-I |
Headers only |
-v |
Verbose |
-s |
Silent mode |
-u user:pass |
Authentication |
-X method |
Request method |
-H header |
Add header |
-d data |
POST data |
-F field=value |
Form data |
HTTP Methods
Method | Description |
---|---|
GET | Retrieve data |
POST | Submit data |
PUT | Update data |
DELETE | Remove data |
HEAD | Headers only |
OPTIONS | Show options |
PATCH | Partial update |
Key Use Cases
- API testing
- File download
- Web scraping
- Data transfer
- Site testing
Examples with Explanations
Example 1: Basic GET
curl https://example.com
Get webpage content
Example 2: Save Output
curl -o file.html https://example.com
Save to file
Example 3: POST Data
curl -X POST -d "data" https://api.example.com
Send POST request
Common Usage Patterns
Download file:
curl -O https://example.com/file
With auth:
curl -u user:pass https://api.example.com
JSON POST:
curl -H "Content-Type: application/json" -d '{"key":"value"}' URL
Security Considerations
- SSL verification
- Credentials handling
- Data exposure
- Cookie security
- Redirect safety
Additional Resources
Best Practices
- Use SSL
- Handle errors
- Set timeouts
- Verify URLs
- Check responses
Output Options
- Headers
- Body
- Progress
- Errors
- Timing
Troubleshooting
- SSL errors
- DNS issues
- Timeout
- Authentication
- Protocol errors
Protocol Support
- HTTP/HTTPS
- FTP/FTPS
- SCP/SFTP
- LDAP
- SMTP/POP3