trying to POST with ruby mechanize

不问归期 提交于 2019-12-21 08:05:19

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/3589260/trying-to-post-with-ruby-mechanize

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!