How to perform a POST request using curl?
Accepted Answer - Simple POST request
To make a simple POST request, use curl -X POST
e.g.
curl -X POST https://www.mysite.com
Sending additional fields
To send additional fields with the POST request, use the -d
flag with data. Note that this will add the Content-Type: application/x-www-form-urlencoded
header to the request.
curl -d "user=admin&pass=secret" -X POST https://www.mysite.com/login
To change the header in order to send a specific data type, such as JSON, use the -H
flag.
curl -d '{user}' -H 'Content-Type: application/json' https://www.mysite.com/login