使用HTTParty登录RESTful Rails应用 [英] Login to a RESTful Rails app with HTTParty
问题描述
我有一个基于干净的RESTful JSON API的Web应用程序,基于 Rails 3.2 , Ruby 1.9 和 Devise 2 。
I have a web app with a clean RESTful JSON API, based on Rails 3.2, Ruby 1.9 and Devise 2.
我想基于 HTTParty 网络客户端编写一个小的脚本,以便经常执行某些操作(使用crontab)。但是我们如何登录并使会话保持打开状态(会话ID由HTTP HEADER传递,并可能存储在cookie中)。
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
我个人使用HTTParty启动了一个项目,并移至RestClient,因为行为似乎更直接了。检出以下网址的 cookies部分:
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
这篇关于使用HTTParty登录RESTful Rails应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!