<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
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:<div><br class="webkit-block-placeholder"></div><div>agent.get(url).code == "403"</div><div><br class="webkit-block-placeholder"></div><div>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):</div><div><br class="webkit-block-placeholder"></div><div>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</div><div><br class="webkit-block-placeholder"></div><div>Or something like that anyway.... I'm sure there's a prettier way to do that search.  Check out <a href="http://code.whytheluckystiff.net/hpricot/wiki/HpricotBasics">http://code.whytheluckystiff.net/hpricot/wiki/HpricotBasics</a></div> <div><div><div> for some more info on the search syntax.</div><div><br class="webkit-block-placeholder"></div><div>-Mat</div><div><br class="webkit-block-placeholder"></div><div>On Jul 16, 2007, at 12:13 PM, hazynrg wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Okay, i now understand.<br>Should i get the "302" in dorf1.code? i have 200 there :(<br>Do you have any idea on the way to check that the access have been granted (or not)?<br><br><div><span class="gmail_quote">2007/7/16, Mat Schaffer &lt; <a href="mailto:schapht@gmail.com">schapht@gmail.com</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style=""><div><span class="e" id="q_113cf672adfae7d0_1"> <div><div>On Jul 15, 2007, at 9:35 AM, hazynrg wrote:</div><br><blockquote type="cite">Hello,<br>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.<br><br> require 'rubygems'<br>require 'mechanize'<br>agent = WWW:Mechanize.new ()<br>login = agent.get("<a href="http://server/login.php" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://server/login.php</a>")<br>form = login.forms.action("dorf1.php")<br>form.fields[2].value = "wronguser"  # login<br>form.fields [3].value = "wrongpass"  # password<br>dorf1 = form.submit ()<br>dorf1.uri<br>    # =&gt; #&lt;URI::<a href="HTTP:0x15af2e04dc7c" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">HTTP:0x15af2e04dc7c</a> URL:<a href="http://server/dorf1.php" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://server/dorf1.php</a>&gt;<br><br>But the page we got was " login.php" (a bit altered: "access denied", etc.)<br>So the URI of the page returned by form.submit() isn't updated if there is a redirect, please fix :) <br>Best regards.</blockquote></div><br></span></div><div>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.</div><span class="sg"><div>-Mat</div></span></div><br>_______________________________________________ <br>Mechanize-users mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Mechanize-users@rubyforge.org">Mechanize-users@rubyforge.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://rubyforge.org/mailman/listinfo/mechanize-users" target="_blank"> http://rubyforge.org/mailman/listinfo/mechanize-users</a><br></blockquote></div><br><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Mechanize-users mailing list</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="mailto:Mechanize-users@rubyforge.org">Mechanize-users@rubyforge.org</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="http://rubyforge.org/mailman/listinfo/mechanize-users">http://rubyforge.org/mailman/listinfo/mechanize-users</a></div> </blockquote></div><br></div></body></html>