• 用户提交包含一些基本数据的表单。
  • 数据通过 Controller 中的操作接收和处理,并添加了更多需要保持私有(private)状态的信息。
  • 然后,我需要将来自 Controller 的所有组合数据发送到外部网站的发帖请求。

  • 做这个的最好方式是什么?

    最佳答案

    最简单的方法是使用ruby核心库:

    require "uri"
    require "net/http"
    
    params = {'box1' => 'Nothing is less important than which fork you use. Etiquette is the science of living. It embraces everything. It is ethics. It is honor. -Emily Post',
    'button1' => 'Submit'
    }
    x = Net::HTTP.post_form(URI.parse('http://www.interlacken.com/webdbdev/ch05/formpost.asp'), params)
    puts x.body
    

    专家提示:使用delayed_job或background_rb等gem进行异步请求

    10-07 12:30
    查看更多