1
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::ResponseCodeError如下。我真的没有在我的代码中看到任何错误,任何人都可以让我知道这是代码错误还是服务器端的问题(比如服务器阻止表单自动提交)?

C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.4/lib/mechanize/http/agent.rb:29 1:in 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:inpost_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:insubmit' from auto_post.rb:27:in block in <main>' from (eval):23:inform_with' from auto_post.rb:13:in `'

4

1 回答 1

1

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

agent.set_proxy 'localhost', 8888

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

于 2012-05-09T09:25:19.793 回答