views:

87

answers:

2

Hi, thanks for reading this.

I was wondering if I have some simple authentication system in place, like authlogic, how does one use curl to post and put data and, even before talking about posting and putting data, how does one "login" with curl and have the server remember or have curl remember that it is logged in?

if you were to choose, would you rather use XML or JSON to post data? And any advice on how to make this posting secure?

Thank You.

+1  A: 

Find the URI that the login form posts to, then POST the relevant data. For example:

curl -X POST -d 'login=foo&password=bar' http://example.com/login
John Feminella
say I did that, and then I wanted to add an article to rails by curl -X POST -d 'article[title]=itablet' -d 'article[body]=lorem ipsum' http://dns/articlesbecause the new action and the create action is 'behind' the layer of the authentication, will curl remember the 'session' that it got from logging in in the previous line?
Nik
A: 

Hi All, I think I got it

So to add that artcile with title and body. 1) login: curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST http://example.com/login -d "{\"user_session\" : { \"username\" : \"someuser\", \"password\" : \"somepassword\"}}" -c example_cook.txt

Because I am using Rails, I have to use json or xml so to avoid the need for authenticity token. Then I save the cook in example_cook.txt for the next step

curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST http://example.com/articles -d "{\"articles\" : { \"title\" : \"lorem\", \"body\" : \"ipsum\"}}" -b example_cook.txt

calling the '-b example_cook.txt' will tell curl to use that session information which the server needs for authenticating you.

That's it!

Regards

Nik