YouTube Icon

Code Playground.

How to make a POST request with cURL

CFG

How to make a POST request with cURL

Twist is an order line utility for moving information from or to a distant worker utilizing one of the upheld conventions. It is introduced of course on macOS and most Linux conveyances. 

Twist is utilized by engineers for testing APIs , seeing reaction headers, and making HTTP demands. 

In this article, we will disclose how to utilize cURL to make POST demands. The HTTP POST technique is utilized to send information to the far off worker. 

Making a POST request

curl -X POST [options] [URL]

The - X choice indicates which HTTP demand strategy will be utilized when speaking with the far off worker. 

The kind of the solicitation body is demonstrated by its Content-Type header. 

By and large, a POST demand is sent by means of a HTML structure. The information send to the structure is normally encoded in either multipart/structure information or application/x-www-structure urlencoded content sort. 

To make a POST demand, utilize the - F choice, trailed by the field=value pair. The accompanying model tells the best way to make a POST solicitation to a structure that has "name" and "email" fields: 

curl -X POST -F 'name=linuxize' -F 'email=linuxize@example.com' https://example.com/contact.php

When the - F alternative is utilized, twist sends the information utilizing the multipart/structure information Content-Type. 

Another approach to make a POST demand is to utilize the - d alternative. This makes twist send the information utilizing the application/x-www-structure urlencoded Content-Type. 

curl -X POST -d 'name=linuxize' -d 'email=linuxize@example.com' https://example.com/contact.php

On the off chance that the - d alternative is utilized more than once you can combine the information utilizing the and image: 

curl -X POST -d 'name=linuxize&email=linuxize@example.com' https://example.com/contact.php

Indicating the Content-Type 

To set a particular header or Content-Type utilize the - H choice. The accompanying order sets the POST demand type to application/json and sends a JSON object: 

curl -X POST -H "Content-Type: application/json" \
    -d '{"name": "linuxize", "email": "linuxize@example.com"}' \
    https://example/contact

 Transferring Files 

curl -X POST -F 'image=@/home/user/Pictures/wallpaper.jpg' http://example.com/upload

Conclusion

We've told you the best way to utilize twist to make POST demands. For more data about twist, visit the Curl Documentation page. 

On the off chance that you have any inquiries or input, don't hesitate to leave a remark.




CFG