In cURL, GET and POST requests are the two most commonly used HTTP methods, each with different use cases and parameter configurations.
GET Request
GET requests are used to retrieve data, with parameters typically appended to the URL.
bash# Basic GET request curl https://api.example.com/users # With query parameters curl "https://api.example.com/users?page=1&limit=10" # With request headers curl -H "Authorization: Bearer token123" \ -H "Accept: application/json" \ https://api.example.com/users # Show response headers curl -i https://api.example.com/users # Show only response headers curl -I https://api.example.com/users
POST Request
POST requests are used to submit data, requiring -X POST to specify the method and -d to pass data.
bash# Send JSON data curl -X POST https://api.example.com/users \ -H "Content-Type: application/json" \ -d '{"name":"John","email":"john@example.com"}' # Send form data curl -X POST https://api.example.com/login \ -d "username=admin&password=123456" # Read data from file curl -X POST https://api.example.com/upload \ -H "Content-Type: application/json" \ -d @data.json # Upload file curl -X POST https://api.example.com/upload \ -F "file=@/path/to/file.pdf"
Key Differences
| Feature | GET | POST |
|---|---|---|
| Data Location | URL parameters | Request body |
| Data Size | Limited by URL length | Unlimited |
| Security | Parameters visible | Relatively secure |
| Caching | Cacheable | Not cached |
| Idempotency | Idempotent | Non-idempotent |
Common Parameters
-Xor--request: Specify HTTP method-Hor--header: Add request header-dor--data: Send data-For--form: Upload form/file-i: Show response headers and body-I: Show only response headers