tags:

views:

40

answers:

1

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 ?

A: 

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

cam
doesn't seem to work.
Kim Jong Woo
hmm, i hadn't seen post used with a block before. it doesn't appear valid looking at the docs/source. how about: `page = browser.post(...)`. Or the way I typically do it is `browser.post(...); browser.page.do_stuff`
cam
Oh, also I saw that you're nested array syntax is OK per the documetation. I still think the hash looks nicer though ;)
cam
+1, `get` supports a block but `post` does not. You can see it here: http://github.com/tenderlove/mechanize/blob/master/lib/mechanize.rb. @cam, you should edit your answer so it says the right thing.
Isaac Cambron