小编Vij*_*dra的帖子

使用ruby mechanize在浏览器中存储登录会话cookie

我正在尝试登录网站并从rails操作重定向到安全页面.我的代码看起来像这样.

 def redirect_to_external 
   agent = Mechanize.new
   page = agent.get('http://example.com/home.asp')
   login_form = page.form_with(:name => "loginForm")
   login_form.login = 'username'
   login_form.password = 'password'
   agent.submit(login_form)

   #cookies = agent.cookie_jar.store.map {|i|  i} #need to store the cookie with a specific in browser
   redirect_to('http://example.com/admin.asp') #page behind password protection
 end
Run Code Online (Sandbox Code Playgroud)

登录在后台成功,但实际重定向到管理页面再次要求在浏览器中进行身份验证,因为会话cookie未存储在浏览器中.尝试存储cookie cookie_jar,但找不到确切的方法.有人可以帮助我吗?

ruby cookies ruby-on-rails mechanize

9
推荐指数
2
解决办法
5448
查看次数

标签 统计

cookies ×1

mechanize ×1

ruby ×1

ruby-on-rails ×1