尝试使用ruby mechanize进行POST

时间:2010-08-28 02:54:06

标签: ruby mechanize

我使用firefox插件LiveHTTPheaders捕获了登录HTTP标头。

我找到了以下网址和变量。

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

这是我正在运行的代码:

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

然而,这没有给我什么!我的帖子参数有问题吗?

1 个答案:

答案 0 :(得分:19)

post()不会阻止。试试这个:

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

编辑:更改准确性