Sunday, April 11, 2021

How to send a HTTP POST request using curl from the commandline

curl POST request with no data:

curl -X POST http://URL/example.php

curl POST request with data:

curl -d "data=foo&data2=bar" http://example.com/example.cgi

curl POST request with data, alternative way:

curl -X POST -F "name=user" -F "password=test" http://example.com/example.php

curl POST with a file:

curl -X POST -F "image=@/local_path/example.jpeg" http://example.com/uploadform.cgi

curl POST JSON data

curl -H "Content-Type: application/json" -X POST -d '{"user":"bob","pass":"123"}' http://example.com/