【问题标题】:Submit post and get and receive the response page in ruby (external website)提交帖子并获取并接收 ruby​​ 中的响应页面(外部网站)
【发布时间】:2012-04-21 15:07:28
【问题描述】:

我知道要做一个简单的页面:

require 'net/http'

source = Net::HTTP.get('example.com', '/index.html')

但是如何从表单中发布帖子并获取返回提交数据结果的页面?有可能吗?

【问题讨论】:

    标签: ruby-on-rails ruby forms form-submit


    【解决方案1】:

    根据 Net::HTTP doc 你可以这样做

    res = Net::HTTP.post_form("example.com/index.html", 'q' => 'ruby', 'max' => '50')
    puts res.body
    

    http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-c-post_form

    【讨论】:

      【解决方案2】:

      一个非常简单的方法是使用resttclient gem:

      require 'rest_client'
      result = RestClient.post 'http://example.com/resource', :param1 => 'one'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-13
        相关资源
        最近更新 更多