I have this code, and I login successfully:
require 'mechanize'
require 'logger'
agent = Mechanize.new{|a| a.log = Logger.new(STDERR) }
agent.read_timeout = 60
def add_cookie(agent, uri, cookie)
uri = URI.parse(uri)
Mechanize::Cookie.parse(uri, cookie) do |cookie|
agent.cookie_jar.add(uri, cookie)
end
end
page = agent.get "http://www.webpage.com"
form = page.forms.first
form.correo_ingresar = "user"
form.password = "password"
page = agent.submit form
myarray = page.body.scan(/SetCookie\(\"(.+)\", \"(.+)\"\)/)
After I login I do not get redirected, so I looked at the webpage and Java is the one redirecting me, but if I use page = agent.get("http://webpage.com") all session cookies are deleted. And I have to login again , and it is a cycle because I don’t get past that. I already tried several recommendations like ignore_discard
It looks like you have the right code to add the cookie but forgot to call it.
At the end try: