Ruby on rails 使用curl登录并使用designe在rails中发布
我正在尝试创建一个bash脚本,使用curl登录到一个rails应用程序,该应用程序在表单上使用design和post 到目前为止,我可以做到:Ruby on rails 使用curl登录并使用designe在rails中发布,ruby-on-rails,authentication,curl,devise,Ruby On Rails,Authentication,Curl,Devise,我正在尝试创建一个bash脚本,使用curl登录到一个rails应用程序,该应用程序在表单上使用design和post 到目前为止,我可以做到: #!/bin/bash curl \ --verbose \ --request GET \ -c cookie \ http://localhost:3000/login > tmpsession # the ff is a hack to get the authenticity_token from the form #
#!/bin/bash
curl \
--verbose \
--request GET \
-c cookie \
http://localhost:3000/login > tmpsession
# the ff is a hack to get the authenticity_token from the form
# and join it with the file 'data' for posting with curl
csrf_token=`cat tmpsession|grep 'authenticity_token'|grep -o 'authenticity_token.*' |grep -o 'value=.*' |cut -d ' ' -f1|cut -d \" -f2`
echo "authenticity_token=" > data ; echo $csrf_token >> data; echo "&" >> data; cat samplepost >> data
curl \
--verbose \
-b cookie \
--request POST \
--data "user[username=admin&user[password]=xxpasswordxx&authenticity_token=$csrf_token" \
http://localhost:3000/login
此时,我被重定向到管理/索引页面,在那里它会在过滤器之前通过redirect\u if\u not\u admin
但是,当我尝试这样做时:
curl \
--verbose \
-b cookie \
--request POST \
--data @data
http://localhost:3000/admin/posts
我在日志中得到一个过滤器链暂停为:redirect\u if\u admin rendered或redirected
,它告诉我当前没有用户登录
我认为curl将会话存储在cookie中,并将其传递给服务器。有没有办法用curl坚持这样一个疗程?找到答案了吗?@DannyClay:你找到答案了吗?如果有,请告诉我们