问题描述
数据是通过以下操作接收和处理的:控制器和更多需要保持隐私的信息。 然后我需要发送一个post请求到一个外部网站,其中包含所有来自控制器。最好的方法是什么?
最简单的方法是使用ruby核心库:
requireuri
需要net / http
params = {'box1'=> 没有什么比您使用哪个分支更重要。礼节是生活的科学。它包含了一切。这是道德。这是荣誉。 -Emily Post',
'button1'=> '提交'
}
x = Net :: HTTP.post_form(URI.parse('http://www.interlacken.com/webdbdev/ch05/formpost.asp'),params)
提交x.body
专业提示:使用像或background_rb
取自以下示例: a href =http://biodegradablegeek.com/2008/04/how-to-post-form-data-using-ruby/ =noreferrer> http://biodegradablegeek.com/2008/04/how -to-post-form-data-using-ruby /
User submits a form with some basic data.
The data is received and treated by an action in the controller and more information that needs to remain private is added.
Then I need to send a post request to an external website with all of the combined data from the controller.
What is the best way to do this?
The simpliest way is using ruby core library:
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
Pro Tip: Do an asynchronous request, using a gem like delayed_job or background_rb
Example taken from: http://biodegradablegeek.com/2008/04/how-to-post-form-data-using-ruby/
这篇关于在控制台中向Rails中的另一个网站提交POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!