问题
I have a web app with a clean RESTful JSON API, based on Rails 3.2, Ruby 1.9 and Devise 2.
I would like to write a small script based on HTTParty web client in order to perform some actions frequently (with a crontab). But how can we sign in and keep the session open (with the session id passed by HTTP HEADER, and maybe stored in a cookie).
I really have no experience about this aspect.
回答1:
According to this mailing list comment as of January, may not be possible:
https://groups.google.com/forum/#!searchin/httparty-gem/cookie/httparty-gem/H2me9zB1mEI/RNy3pdSzWnsJ
I personally started a project with HTTParty, and moved to RestClient because the behavior seems was more straightforward IMHO. Checkout the 'cookies' section of:
https://github.com/archiloque/rest-client
...may suite your needs.
Justin
来源:https://stackoverflow.com/questions/10057770/login-to-a-restful-rails-app-with-httparty