在控制台中向Rails中的另一个网站提交POST数据 [英] Submit POST data from controller to another website in Rails

查看:133
本文介绍了在控制台中向Rails中的另一个网站提交POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据是通过以下操作接收和处理的:控制器和更多需要保持隐私的信息。 然后我需要发送一个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

专业提示:使用像 delayed_job 或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 /


  1. User submits a form with some basic data.

  2. The data is received and treated by an action in the controller and more information that needs to remain private is added.

  3. 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数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆