How to Perform a POST Request Using Curl

9

Curl command is known as a “Client URL” and universally used command line utility obtainable for Windows, Mac, and Linux working techniques. This command makes use of totally different protocols similar to HTTPS, FTP, SMP, etc to down load photographs and documents from the URL, ship statistics to the server, entry statistics from the URL, and get the server content material. Sending statistics to the server is accomplished using Post request even as getting statistics from the server is accomplished using Get request.

This article will show learn how to participate in a POST request making use of the curl command.

How to Perform a POST Request Using curl Command?

In a POST request, the “POST” is an HTTP request procedure utilized to ship requests or statistics to the server using HTTPS or HTTP protocol. The “curl” command helps us to ship a POST request to the server using the URL.

Prerequisites: Install Curl Command

To ship a POST request to a server using the Client URL, first, installation the “curl” command on Ubuntu making use of the “apt install curl” with “sudo” rights:

Send Simple Post Request Using Curl

In order to ship effortless POST requests using the curl command, make the most of the “curl -X POST ” command:

curl -X POST https://reqbin.com/

Here, “-X” is used to decide upon the HTTP request procedure similar to the “POST” procedure.

Send Data in Post Request Using Curl

The POST request procedure is notably used to ship or switch statistics to a server or specified URL. To ship statistics to the server, make the most of the subsequent possibilities:

    • -d” possibility specifies the statistics that has to be transferred.
    • -H” defines the header content material variety or statistics variety that’s transferred using a POST request.
    • -X” is utilized to opt for and use the POST request procedure with URL:

curl -d ‘{“e-mail”:”rafia@gmail.com”,”password”:”password123″}’ -H “Content-Type: multipart/form-data” -X POST https://reqbin.com/echo/put up/json

Write Response of Post Request in Output File

The output or response of a POST request could be saved or overwritten to a file making use of the “-o” possibility. For occasion, now we have saved the response within the “test.html” file:

curl -d ‘{“e-mail”:”rafia@gmail.com”, “password”:”password123″}’ -H “Content-Type: multipart/form-data” -X POST https://reqbin.com/echo/put up/json -o take a look at.html


After that, execute the file and investigate the output or response of POST request:

Send File in Post Request Using Curl

POST requests not solely ship statistics but additionally can alternate documents as effectively. In order to ship the whole file in POST request, first, create the file making use of the “touch” command and save the content material into the file.

For occasion, now we have created “file.txt”:

Next, make the most of the “curl” command together with the POST request as talked about within the under command:

curl –form “fileupload=@file.txt” -X POST https://reqbin.com/echo/put up

Here, “–form” possibility is used to ship the kind statistics within the POST request:


That is all about sending a POST request making use of the “curl” command.

Conclusion

To participate in a POST request making use of the “curl” command, first, installation the “curl” in your system using the “sudo apt install curl” command. After that, ship the POST request within the “curl” command making use of the “curl -X POST ” command together with possibilities similar to “-d”, “-H”, and “–form”. This put up has illustrated learn how to participate in a POST request making use of the curl command.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More