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"
thanks for the cron code
ReplyDeletethanks for posting.. exactly what I was looking for :)
ReplyDeleteThats right, I'm gonna try it out right now and comment how its going
ReplyDeleteI tried out but with no success, I might have to pass my password and user name to be able to , I guess....
ReplyDeleteDoes 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
ReplyDelete- 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:
ReplyDelete-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 :)
ReplyDeleteInteresting 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:)
ReplyDelete[...] HTTP POST with curl [...]
ReplyDeleteUnix 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.
ReplyDeleteHi,
ReplyDeleteCan 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.
I am struggling to POST data read from a remote file (say http:example1.com/mydata.xml) to a serviceendpoint. The following command doesn't work.
ReplyDeleteCURL -POST -d @http://example1.com/mydata.xml http://example2.com/serviceendpoint
Please help
hey everyone, i am new to curl, can anyone tell me where should i put this line code?
ReplyDelete