Hello, I have a login form on /login.php which POSTs to /dorf1.php when access is granted and to /login.php when it is denied. require ''rubygems'' require ''mechanize'' agent = WWW:Mechanize.new() login = agent.get("http://server/login.php") form = login.forms.action("dorf1.php") form.fields[2].value = "wronguser" # login form.fields[3].value = "wrongpass" # password dorf1 = form.submit() dorf1.uri # => #<URI::HTTP:0x15af2e04dc7c URL:http://server/dorf1.php> But the page we got was "login.php" (a bit altered: "access denied", etc.) So the URI of the page returned by form.submit() isn''t updated if there is a redirect, please fix :) Best regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20070715/f02ca66b/attachment.html
On Jul 15, 2007, at 9:35 AM, hazynrg wrote:> Hello, > I have a login form on /login.php which POSTs to /dorf1.php when > access is granted and to /login.php when it is denied. > > require ''rubygems'' > require ''mechanize'' > agent = WWW:Mechanize.new () > login = agent.get("http://server/login.php") > form = login.forms.action("dorf1.php") > form.fields[2].value = "wronguser" # login > form.fields [3].value = "wrongpass" # password > dorf1 = form.submit() > dorf1.uri > # => #<URI::HTTP:0x15af2e04dc7c URL:http://server/dorf1.php> > > But the page we got was " login.php" (a bit altered: "access > denied", etc.) > So the URI of the page returned by form.submit() isn''t updated if > there is a redirect, please fix :) > Best regards.Mechanize doesn''t support javascript, so if you''re changing target based on that, it won''t work. If you''re using a html meta tag to redirect from dorf1.php back to login.php on failure, I don''t think that would work either. But a 302 (header("Location: login.php")) should work. -Mat -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20070716/f6122411/attachment-0001.html
Okay, i now understand. Should i get the "302" in dorf1.code? i have 200 there :( Do you have any idea on the way to check that the access have been granted (or not)? 2007/7/16, Mat Schaffer <schapht at gmail.com>:> > On Jul 15, 2007, at 9:35 AM, hazynrg wrote: > > Hello, > I have a login form on /login.php which POSTs to /dorf1.php when access is > granted and to /login.php when it is denied. > > require ''rubygems'' > require ''mechanize'' > agent = WWW:Mechanize.new () > login = agent.get("http://server/login.php") > form = login.forms.action("dorf1.php") > form.fields[2].value = "wronguser" # login > form.fields [3].value = "wrongpass" # password > dorf1 = form.submit() > dorf1.uri > # => #<URI::HTTP:0x15af2e04dc7c URL:http://server/dorf1.php> > > But the page we got was " login.php" (a bit altered: "access denied", > etc.) > So the URI of the page returned by form.submit() isn''t updated if there is > a redirect, please fix :) > Best regards. > > > Mechanize doesn''t support javascript, so if you''re changing target based > on that, it won''t work. If you''re using a html meta tag to redirect from > dorf1.php back to login.php on failure, I don''t think that would work > either. But a 302 (header("Location: login.php")) should work. > -Mat > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20070716/dbed7b41/attachment.html
At the HTTP level, access granted (or not) is determined by the return codes (403 being a common access denied message). Mechanize can access this via Page#code: agent.get(url).code == "403" But if your "access denied" message is on an HTML page that gets returned with a 200 code, consider using Page#search to look for the message (assuming you have some class tags that could identify it): agent.get(url).search("div.error").find { |e| e.inner_html =~ /denied/ i } # find the first div of class "error" that has "denied" in it''s contents Or something like that anyway.... I''m sure there''s a prettier way to do that search. Check out http://code.whytheluckystiff.net/hpricot/ wiki/HpricotBasics for some more info on the search syntax. -Mat On Jul 16, 2007, at 12:13 PM, hazynrg wrote:> Okay, i now understand. > Should i get the "302" in dorf1.code? i have 200 there :( > Do you have any idea on the way to check that the access have been > granted (or not)? > > 2007/7/16, Mat Schaffer < schapht at gmail.com>: > On Jul 15, 2007, at 9:35 AM, hazynrg wrote: > >> Hello, >> I have a login form on /login.php which POSTs to /dorf1.php when >> access is granted and to /login.php when it is denied. >> >> require ''rubygems'' >> require ''mechanize'' >> agent = WWW:Mechanize.new () >> login = agent.get(" http://server/login.php") >> form = login.forms.action("dorf1.php") >> form.fields[2].value = "wronguser" # login >> form.fields [3].value = "wrongpass" # password >> dorf1 = form.submit () >> dorf1.uri >> # => #<URI::HTTP:0x15af2e04dc7c URL: http://server/dorf1.php> >> >> But the page we got was " login.php" (a bit altered: "access >> denied", etc.) >> So the URI of the page returned by form.submit() isn''t updated if >> there is a redirect, please fix :) >> Best regards. > > Mechanize doesn''t support javascript, so if you''re changing target > based on that, it won''t work. If you''re using a html meta tag to > redirect from dorf1.php back to login.php on failure, I don''t think > that would work either. But a 302 (header("Location: login.php")) > should work. > -Mat > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20070716/752b33f8/attachment.html