ruby on rails - Cannot sign in using form with Mechanize -


i trying submit form mechanize. nothing happens on submit. login page again.

the form:

http://affilate.mikkelsenmedia.dk/partnersystem/mylogins.php

require 'mechanize' agent = www::mechanize.new agent.get("http://affilate.mikkelsenmedia.dk/partnersystem/mylogins.php")  form = agent.page.forms.first form.username = 'username' form.password = 'password' form.submit 

live http log when login in browser:

http://affilate.mikkelsenmedia.dk/partnersystem/mylogins.php  post /partnersystem/mylogins.php http/1.1 host: affilate.mikkelsenmedia.dk user-agent: mozilla/5.0 (windows; u; windows nt 6.1; da; rv:1.9.2.13) gecko/20101203 firefox/3.6.13 accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-language: da,en-us;q=0.7,en;q=0.3 accept-encoding: gzip,deflate accept-charset: iso-8859-1,utf-8;q=0.7,*;q=0.7 keep-alive: 115 connection: keep-alive referer: http://affilate.mikkelsenmedia.dk/partnersystem/mylogins.php cookie: xxx content-type: application/x-www-form-urlencoded content-length: 47 username=username&password=password&send=submit http/1.1 200 ok date: fri, 18 feb 2011 17:07:15 gmt server: apache/2.0.63 (centos) x-powered-by: php/5.1.6 expires: thu, 19 nov 1981 08:52:00 gmt cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 pragma: no-cache content-length: 77 connection: close content-type: text/html; charset=utf-8 

console:

irb(main):001:0> require 'mechanize' => true irb(main):002:0> agent = mechanize.new { |agent| irb(main):003:1*   agent.user_agent_alias = 'mac safari' <"http://affilate.mikkelsenmedia.dk/partnersystem/mylogins.php") => #<mechanize::page  {url   #<uri::http:0x2a1c770 url:http://affilate.mikkelsenmedia.dk/partnersystem/mylo gins.php>}  {meta}  {title "partner system - log-in"}  {iframes}  {frames}  {links}  {forms   #<mechanize::form    {name "loginform"}    {method "post"}    {action "mylogins.php"}    {fields     #<mechanize::form::text:0x2836680      @name="username",      @node=       #(element:0x141b3e8 {         name = "input",         attributes = [           #(attr:0x13e4458 { name = "type", value = "text" }),           #(attr:0x13e4440 { name = "name", value = "username" }),           #(attr:0x13e43e0 { name = "size", value = "30" })]         }),      @value="">     #<mechanize::form::field:0x2836230      @name="password",      @node=       #(element:0x141b22c {         name = "input",         attributes = [           #(attr:0x13ac148 { name = "type", value = "password" }),           #(attr:0x13ac13c { name = "name", value = "password" }),           #(attr:0x13ac10c { name = "size", value = "30" })]         }),      @value="">}    {radiobuttons}    {checkboxes}    {file_uploads}    {buttons     #<mechanize::form::submit:0x2835f90      @name="send",      @node=       #(element:0x141b01c {         name = "input",         attributes = [           #(attr:0x13702e0 { name = "type", value = "submit" }),           #(attr:0x13702d4 { name = "name", value = "send" }),           #(attr:0x13702c8 { name = "class", value = "style2" }),           #(attr:0x13702bc { name = "value", value = "submit" })]         }),      @value="submit">}>}>  irb(main):006:0>   form = agent.page.forms.first irb(main):007:0>   form.username = 'username' => "username" irb(main):008:0>   form.password = 'password' => "password" irb(main):009:0>   form.submit => #<mechanize::page  {url   #<uri::http:0x2a82e78 url:http://affilate.mikkelsenmedia.dk/partnersystem/mylo gins.php>}  {meta}  {title "partner system - log-in"}  {iframes}  {frames}  {links}  {forms   #<mechanize::form    {name "loginform"}    {method "post"}    {action "mylogins.php"}    {fields     #<mechanize::form::text:0x2a52c50      @name="username",      @node=       #(element:0x1529694 {         name = "input",         attributes = [           #(attr:0x1513c14 { name = "type", value = "text" }),           #(attr:0x1513c08 { name = "name", value = "username" }),           #(attr:0x1513bfc { name = "size", value = "30" })]         }),      @value="">     #<mechanize::form::field:0x2a52998      @name="password",      @node=       #(element:0x1529550 {         name = "input",         attributes = [           #(attr:0x15121d4 { name = "type", value = "password" }),           #(attr:0x15121c8 { name = "name", value = "password" }),           #(attr:0x15121bc { name = "size", value = "30" })]         }),      @value="">}    {radiobuttons}    {checkboxes}    {file_uploads}    {buttons     #<mechanize::form::submit:0x2a52758      @name="send",      @node=       #(element:0x152940c {         name = "input",         attributes = [           #(attr:0x151062c { name = "type", value = "submit" }),           #(attr:0x1510614 { name = "name", value = "send" }),           #(attr:0x1510608 { name = "class", value = "style2" }),           #(attr:0x15105fc { name = "value", value = "submit" })]         }),      @value="submit">}>}>  irb(main):010:0> 

the server checks presence of submit button parameter 'send'.

add line before form.submit

form.add_field! 'send','submit' 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -