HTTP POST with curl
June 29, 2005 · Posted in Computer
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” “http://www.domain.com/file.php”
Posting the contents of a file
curl -d @file_to_post.txt “http://www.domain.com/file.php”
Comments
9 Responses to “HTTP POST with curl”
Leave a Reply

thanks for the cron code
thanks for posting.. exactly what I was looking for
Thats right, I’m gonna try it out right now and comment how its going
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!
andy
curl -u “username:password” http://www.whatever.com/whatever
- or -
curl http://username:password@www.whatever.com/whatever
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.
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}
Thank you very much, it was very useful for me
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:)
[...] HTTP POST with curl [...]