【问题标题】:Ruby form auto submission Mechanize::ResponseCodeErrorRuby 表单自动提交 Mechanize::ResponseCodeError
【发布时间】:2012-05-09 08:33:17
【问题描述】:
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: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' 来自 auto_post.rb:27:in block in <main>' from (eval):23:inform_with' 来自 auto_post.rb:13:in `'

【问题讨论】:

  • 它说 500 Internal Server Error,你应该检查你的服务器日志。
  • 感谢 KARASZI István 的回复,问题是我没有访问服务器的权限...有没有其他方法可以找出到底哪里出了问题以便我修复它?跨度>
  • 您可以查看实际响应,可能错误在里面(使用tcpdump或浏览器中开发者工具的网络部分)。

标签: ruby error-handling mechanize


【解决方案1】:

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

agent.set_proxy 'localhost', 8888

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 2014-04-12
    • 2012-01-24
    相关资源
    最近更新 更多