Wednesday, June 29, 2005

HTTP POST with curl

I keep forgetting how to perform a HTTP POST with curl, so I want to write this down so I don't forget.

Posting a string:

curl -d "String to post" ""

Posting the contents of a file

curl -d @file_to_post.txt ""


  1. thanks for posting.. exactly what I was looking for :)

  2. Thats right, I'm gonna try it out right now and comment how its going

  3. I tried out but with no success, I might have to pass my password and user name to be able to , I guess....
    Does any body knows how to pass password and user name while posting with curl?
    Thanks for any hint!

  4. curl -u "username:password"
    - or -
    If it's a site with a self-signed cert and you have to connect over https, you may have to add the --insecure (I think the short version is -k but don't quote me on that) option to keep curl from yelling at you about certificate mismatches.

  5. In some cases, xml-based web service API's require this header in order to work:
    -H "Content-Type: text/xml" . Placed after the data and before the url, of course:

    curl --silent --data-ascii "${myrequest}" -H "Content-Type: text/xml" http://${myxmlservice}

  6. Thank you very much, it was very useful for me :)

  7. Interesting way to not lose track, I have one file were I stick all code related snippets that I might need later, its getting a little large, maybe it is time for a new strategy:)

  8. Unix provides so many ways to do things. wget also has similar functionality in case curl does not fit the bill. Then again you should be looking at sftp too.

  9. Hi,

    Can we use curl to write data into a log file? Curl will be sending the data but what I want is to able to write the data into a logfile on the other end.

  10. I am struggling to POST data read from a remote file (say to a serviceendpoint. The following command doesn't work.

    CURL -POST -d @

    Please help

  11. hey everyone, i am new to curl, can anyone tell me where should i put this line code?


Revolutionizing Air Quality Monitoring: How I Upgraded Our System with Mila Integration for Smart Home Automation

In this blog post , I explained how I set up an air quality monitoring system for our neighborhood. With this setup, we can keep an eye on t...