Is there a way to use curl to send a POST request without sending any data?
We usually post like:
curl --data @C:\mydata.txt http://1.2.3.4/myapi
If you omit the --data
you are doing a GET. How can you omit it and still do a POST?
By default you use curl without explicitly saying which request method to use. If you just pass in a HTTP URL like curl http://example.com it will use GET. If you use -d or -F curl will use POST, -I will cause a HEAD and -T will make it a PUT.
curl's --data will by default send Content-Type: application/x-www-form-urlencoded in the request header. However, when using Postman's raw body mode, Postman sends Content-Type: text/plain in the request header. It should be noted though that the body part is sent exactly the same. This just changes a header.
Randomly found the solution on another post:
curl -X POST http://example.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With