POST with curl without sending data

Curl

Curl Problem Overview


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?

Curl Solutions


Solution 1 - Curl

Randomly found the solution on another post:

curl -X POST http://example.com

Solution 2 - Curl

Another option is sending a request with empty body, like so:

curl http://example.com -d {}

Solution 3 - Curl

This is a bit of a hack, but you could always provide an empty --data file.

Alternately

cat /dev/null | curl --data @- http://...

Solution 4 - Curl

In case of libcurl with PHP:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');

Solution 5 - Curl

If you need to be authenticated then below is the command:

curl -X POST -u username:password http://example.com

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarcus LeonView Question on Stackoverflow
Solution 1 - CurlMarcus LeonView Answer on Stackoverflow
Solution 2 - CurlAfshin MehrabaniView Answer on Stackoverflow
Solution 3 - CurlhempView Answer on Stackoverflow
Solution 4 - CurldogView Answer on Stackoverflow
Solution 5 - CurlKelvin MurumbaView Answer on Stackoverflow