Ruby表单自动提交Mechanize :: ResponseCodeError

时间:2012-05-09 08:33:17

标签: ruby error-handling mechanize

submit_form = agent.get("http://sample.com/NewTask.aspx").form("aspnetForm") do |f|
    f["ctl00$ContentPlaceHolder1$txtNumber"] = "1234",
    f["ctl00$ContentPlaceHolder1$cmbText"] = "test",
    f["ctl00$ContentPlaceHolder1$FUpload$fu"] = "",
    f["ctl00$ContentPlaceHolder1$btn"] = "test"
    f.submit(f.button_with(:name => "ctl00$ContentPlaceHolder1$btnOK"))
end

这是我为使用Ruby的mechanize lib的表单自动提交编写的代码,它返回Mechanize::ResponseCodeError,如下所示。我真的没有看到我的代码中的任何错误,任何人都可以告诉我,如果这是一个代码错误或服务器端的东西(说服务器阻止表单自动提交)?

C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.4/lib/mechanize/http/agent.rb:29 1:在fetch': 500 => Net::HTTPInternalServerError for http://sample.com/NewTask.aspx -- unhandled response (Mechanize::ResponseCodeError) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.4/lib/mechanize.rb:1207:in post_form'中         来自C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.4/lib/mechanize.rb:515:in submit' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.4/lib/mechanize/form.rb:178:in submit'         来自auto_post.rb:27:in block in <main>' from (eval):23:in form_with'         来自auto_post.rb:13:在''

1 个答案:

答案 0 :(得分:1)

您需要通过fiddler或charles等调试代理进行代理:

agent.set_proxy 'localhost', 8888

然后代理您的浏览器并比较请求