trying to POST with ruby mechanize

KJW picture KJW · Aug 28, 2010 · Viewed 14.6k times · Source

I've captured the login HTTP headers using firefox plugin LiveHTTPheaders.

I've found the following url and variables.

POST /login
email=myemail%40gmail.com&password=something&remember=1&loginSubmit=Login

And here's the code I am running:

require 'rubygems'
require 'mechanize'


browser = Mechanize.new
browser.post('http://www.mysite.com/login',
[
["email","myemail%40gmail.com"],
["password","something"],
["remember","1"],
["loginSubmit","Login"],
["url"=>""]
]
) do |page|
puts page.body
end

However, this gives me nothing ! is something wrong with my post parameters ?

Answer

cam picture cam · Aug 28, 2010

post() doesn't take a block. Try this:

page = browser.post('http://www.mysite.com/login', {
  "email" => "myemail%40gmail.com",
  "password" => "something",
  "remember" => "1",
  "loginSubmit" => "Login",
  "url" => ""
})

edit: changed for accuracy