Curl
Curl
Basic Usage
- Retrieve a Web Page
1
curl http://example.com
- Save the Output to a File
1
curl -o output.html http://example.com
- Follow Redirects
1
curl -L http://example.com
- HTTP Methods
- GET Request
1
curl -X GET http://example.com
- POST Request
1
curl -X POST -d "param1=value1¶m2=value2" http://example.com
- PUT Request
1
curl -X PUT -d "param1=value1¶m2=value2" http://example.com/resource/1
- DELETE Request
1
curl -X DELETE http://example.com/resource/1
Headers and Authentication
- Set Custom Headers
1
curl -H "Content-Type: application/json" http://example.com
- Send a User-Agent Header
1
curl -A "Mozilla/5.0" http://example.com
- Basic Authentication
1
curl -u username:password http://example.com
- Bearer Token Authentication
1
curl -H "Authorization: Bearer your_token" http://example.com
Data and Files
- Send Form Data
1
curl -F "name=John" -F "file=@photo.jpg" http://example.com/upload
- Send JSON Data
1
curl -X POST -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}' http://example.com/api
- Upload a File
1
curl -T file.txt ftp://example.com/upload/
Advanced Usage
- Handle Cookies
1
curl -c cookies.txt -b cookies.txt http://example.com
- Verbose Output
1
curl -v http://example.com
- Limit Download Rate
1
curl --limit-rate 100K http://example.com
- Specify a Proxy
1
curl -x http://proxy.example.com:8080 http://example.com
- Insecure Connections (ignore SSL certificate errors)
1
curl -k https://example.com
- Download Multiple Files
1
curl -O http://example.com/file1 -O http://example.com/file2
This post is licensed under CC BY 4.0 by the author.