Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to perform a POST request using Curl

Educative Answers Team

Curl is a command-line utility that allows users to create network requests. Curl is accessible on Windows, Linux, and Mac, making it the go-to choice for developers across all platforms.

We can make POST requests with varying levels of detail. Some sample POST requests are given below:

Making a simple POST request

To make a basic POST request using curl, type the following command on your command-line:

curl -X POST

The -X flag specifies a custom request method to use when communicating with the HTTP server. By default, the GET method is used unless some other method is specified.

Sending additional fields with a POST request

Users can send data with the POST request using the -d flag. The following POST request sends a user and a pass field along with their corresponding values.

curl -d "user=user1&pass=abcd" -X POST

POSTing with curl’s -d option will include a default header that looks like: Content-Type: application/x-www-form-urlencoded.

Specifying the Content-Type in POST request

The -H flag can be used to send a specific data type or header with curl. The following command sends a JSON object with the request.

curl -d '{json}' -H 'Content-Type: application/json'

Sending a file using curl

We can also send complete files in the command-line using curl. The command used to do this is:

curl --form "fileupload=@my-file.txt"


Copyright ©2022 Educative, Inc. All rights reserved

View all Courses