HTTP POST is a method used to submit data to be processed to a specified resource on the web. cURL is a versatile tool that allows you to send and retrieve data from servers. It supports a wide range of protocols, including HTTP, HTTPS, FTP, and many more.
In development and testing scenarios, it is common to interact with APIs or web services that require data submission using the POST method. With cURL, you can easily simulate these requests, providing headers, data, or files as needed.
Knowing how to send a POST request with cURL can help in debugging APIs, submitting forms from command line, and automating tasks that require web data submission.
Related: get-request, put-request, delete-request
$ curl -X POST -d "key1=value1&key2=value2" https://www.example.com/post-endpoint
$ curl -X POST -H "Authorization: Bearer YOUR_TOKEN" -d "data=value" https://www.example.com/api/v1/resource
$ curl -X POST -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}' https://www.example.com/api/json-endpoint
Remember to properly format your JSON data and ensure that strings are enclosed in double quotes.
$ curl -X POST -F "file=@/path/to/your/file.jpg" https://www.example.com/upload-endpoint
$ curl -X POST -H "Authorization: Bearer YOUR_TOKEN" -H "Content-Type: application/json" -d '{"key":"value"}' https://www.example.com/api/endpoint
Comment anonymously. Login not required.