HostOnNet Blog

Making POST request with curl

Looking for Linux Server Admin or WordPress Expert? We can help.

For an API request, i need to sent POST request with following data.

Content-Type: application/json


This can be done with following curl command

curl --request POST -H "Content-Type: application/json" --data '{"username":"demouser1","password":"mypassword"}'

Here –request POST tell curl to use POST method for the request. -H specify the header. –data specify POST data to be sent to serer.


boby@hon-pc-01:~ $ curl --request POST -H "Content-Type: application/json" --data '{"username":"hostonnet","password":"assNoPword1"}'
{"userName":"hostonnet","accountAlias":"ZVJ0","locationAlias":"NY1","roles":["AccountAdmin"],"bearerToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ1cm46YXBpLXRpZXIzIiwiYXVkIjoidXJuOnRpZXIzLXVzZXJzIiwibmJmIjoxNDkxODExNTk0LCJleHAiOjE0OTMwMjExOTQsInVuaXF1ZV9uYW1lIjoidG9tbXk0MzA4NyIsInVybjp0aWVyMzphY2NvdW50LWFsaWFzIjoiWlZKMCIsInVybjp0aWVyMzpsb2NhdGlvbi1hbGlhcyI6Ik5ZMSIsInJvbGUiOiJBY2NvdW50QWRtaW4ifQ.D2sdg029yCUyX6gDxxQwbgcTuEoImezIj7vaiytrYPM"}boby@hon-pc-01:~ $

Download Password protected files using curl

curl -u USERNAME:PASSWORD http://url/to/password/protected/file

Posted in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.