Back

CURL, Ruby on Rails, forms and testing forms with CURL

added on :: 10 October 2014

Get the cookie and save it locally

curl http://iamfree.com/notes/new  --cookie-jar cookie | grep csrf


Then post the form

curl -d "note[content]=Look"   -X POST -d 
"note[authenticity_token]=MbnjsEJE+sxufiLEPydqeaGBQFmeWS8xAePJxpK4DeG4TwIy4IuvXbxLijjLp8AFTYDRjp0dc5n1E8SNE/ucQw==" 
 http://iamfree.com/notes  


If you dont want CSRF validations add the bellow line in the controller

protect_from_forgery :except => [:new, :create] 
 
Then to submit a  form

curl -d "note[content]=Look"  http://iamfree.com/notes  method="post"

Also to rather than typing -d all the time you can JSON post it

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST 
-d ' {"user":{"email":"example@example.com", "password":"thatisasecret"}}'
http://iamfree.com/api/v1/sessions



Back