问题描述
我想使用cURL测试我的rails web服务,但到目前为止,我只能在停用 before_filter:authenticate_user!
时。但我想先登录一个先验,然后创建,销毁等。
I want to test my rails web service using cURL, yet so far I could only do it while deactivating before_filter :authenticate_user!
. But I'd like to log in a priori and then create, destroy etc.
我看到使用cURL你可以验证和保存在cookie中的会话信息,你使用的以下请求,但我不能让它与Devise的工作:在我的方案中,用户使用电子邮件/密码组合登录,所以我试试:
I saw that with cURL you can authenticate and save the session info in a cookie, that you use for your following requests, yet I couldn't make it work with Devise: in my scenario, the user logs in using an email/password combination, so I'm trying:
curl \
-X POST \
-d '[email protected]&password=password' \
-c cookie \
http://localhost:3000/users/sign_in > out
我得到: DevContact中的ActionController :: InvalidAuthenticityToken / sessionsController#create
有人可以给我一个想法/示例吗?
Could somebody give me an idea / an example?
谢谢!
推荐答案
这个工作原理:
验证:
curl -H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-X POST http://localhost:3000/users/sign_in \
-d "{'user' : { 'email' : '[email protected]', 'password' : 'password'}}" \
-c cookie
显示 / p>
Show:
curl -H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-X GET http://localhost:3000/pages/1.xml \
-b cookie
这篇关于如何使用cURL在使用Devise的Rails应用程序上进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!