Here’s a cheat sheet for using curl
, a command-line tool for making HTTP requests:
Basic GET Request
Simple GET Request:
curl http://example.com
Follow Redirects:
curl -L http://example.com
Sending Data
POST Request with Data:
curl -X POST -d "key1=value1&key2=value2" http://example.com/resource
POST JSON Data:
curl -X POST -H "Content-Type: application/json" -d '{"key": "value"}' http://example.com/resource
Headers and Cookies
Include Headers:
curl -H "HeaderName: HeaderValue" http://example.com
Include Multiple Headers:
curl -H "Header1: Value1" -H "Header2: Value2" http://example.com
Set Cookie:
curl -b "cookieName=cookieValue" http://example.com
Custom User Agent:
curl -A "CustomUserAgent" http://example.com
Authentication
Basic Authentication:
curl -u username:password http://example.com
File Upload
Upload File:
curl -F "[email protected]" http://example.com/upload
Output Options
Save Output to File:
curl -o output.html http://example.com
Print Headers and Body:
curl -i http://example.com
Print Only Body:
curl -s http://example.com
Other Useful Options
Follow Location Header:
curl -L http://example.com
Limit Time of Request:
curl --max-time 5 http://example.com
Disable SSL Verification:
curl --insecure https://example.com
Show cURL Commands from HTTPie:
curl https://example.com --trace-ascii -
These are just some basic examples of curl
usage. The tool is highly flexible and can be adapted for various HTTP-related tasks. Refer to the official documentation for more detailed options and functionalities.