将 POST 数据从控制器提交到 Rails 中的另一个网站 [英] Submit POST data from controller to another website in Rails

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

问题描述

  1. 用户提交包含一些基本数据的表单.

  1. 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.

最好的方法是什么?

推荐答案

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

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

专业提示:执行异步请求,使用像 delayed_job 或 background_rb

Pro Tip: Do an asynchronous request, using a gem like delayed_job or background_rb

这篇关于将 POST 数据从控制器提交到 Rails 中的另一个网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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