HomeLinuxHow one can Carry out a POST Request Utilizing Curl

How one can Carry out a POST Request Utilizing Curl


Curl command is known as a “Shopper URL” and universally used command line utility obtainable for Home windows, Mac, and Linux working methods. This command makes use of totally different protocols comparable to HTTPS, FTP, SMP, and so forth to obtain photographs and recordsdata from the URL, ship knowledge to the server, entry knowledge from the URL, and get the server content material. Sending knowledge to the server is finished by Put up request whereas getting knowledge from the server is finished by Get request.

This text will display the way to carry out a POST request utilizing the curl command.

How one can Carry out a POST Request Utilizing curl Command?

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

Conditions: Set up Curl Command

To ship a POST request to a server by the Shopper URL, first, set up the “curl” command on Ubuntu utilizing the “apt set up curl” with “sudo” rights:

 

Ship Easy Put up Request Utilizing Curl

In an effort to ship easy POST requests by the curl command, make the most of the “curl -X POST <URL>” command:

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

 
Right here, “-X” is used to pick out the HTTP request methodology such because the “POST” methodology.


 

Ship Knowledge in Put up Request Utilizing Curl

The POST request methodology is especially used to ship or switch knowledge to a server or specified URL. To ship knowledge to the server, make the most of the next choices:

    • -d” choice specifies the information that must be transferred.
    • -H” defines the header content material sort or knowledge sort that’s transferred by a POST request.
    • -X” is utilized to decide on and use the POST request methodology with URL:

 

curl -d ‘{“e-mail”:”[email protected]”,”password”:”password123″}’ -H “Content material-Kind: multipart/form-data” -X POST https://reqbin.com/echo/submit/json

 

 

Write Response of Put up Request in Output File

The output or response of a POST request might be saved or overwritten to a file utilizing the “-o” choice. For example, we now have saved the response within the “take a look at.html” file:

curl -d ‘{“e-mail”:”[email protected]”, “password”:”password123″}’ -H “Content material-Kind: multipart/form-data” -X POST https://reqbin.com/echo/submit/json -o take a look at.html

 

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

Ship File in Put up Request Utilizing Curl

POST requests not solely ship knowledge but additionally can trade recordsdata as effectively. In an effort to ship the complete file in POST request, first, create the file utilizing the “contact” command and save the content material into the file.

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

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

curl –form [email protected] -X POST https://reqbin.com/echo/submit

 
Right here, “–type” choice is used to ship the shape knowledge within the POST request:


 

That’s all about sending a POST request utilizing the “curl” command.

Conclusion

To carry out a POST request utilizing the “curl” command, first, set up the “curl” in your system by the “sudo apt set up curl” command. After that, ship the POST request within the “curl” command utilizing the “curl -X POST <URL>” command together with choices comparable to “-d”, “-H”, and “–type”. This submit has illustrated the way to carry out a POST request utilizing the curl command.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments