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 y开发者_如何学Cou omit the --data
you are doing a GET. How can you omit it and still do a POST?
Randomly found the solution on another post:
curl -X POST http://example.com
Another option is sending a request with empty body, like so:
curl http://example.com -d {}
This is a bit of a hack, but you could always provide an empty --data file.
Alternately
cat /dev/null | curl --data @- http://...
In case of libcurl with PHP:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
If you need to be authenticated then below is the command:
curl -X POST -u username:password http://example.com
精彩评论