我正在尝试登录网站并从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,但找不到确切的方法.有人可以帮助我吗?