Submit POST data from controller to another website in Rails Submit POST data from controller to another website in Rails ruby ruby

Submit POST data from controller to another website in Rails


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


Sorry, I neglected to mention that I was connecting to secure server. This seems to have been the reason that I was getting end of file errors. Adding using 'net/https' and calling use_ssl on connection solved the problem. Thanks for everyones help.

require 'net/https'require 'open-uri'url = URI.parse('https://MY_URL')req = Net::HTTP::Post.new(url.path)req.form_data = datareq.basic_auth url.user, url.password if url.usercon = Net::HTTP.new(url.host, url.port)con.use_ssl = truecon.start {|http| http.request(req)}    

This is based off the source for the post_form method, so i guess I'll give vlad.zloteanu the answer.


If the external server is RESTful, then simply create an ActiveResource model to handle your data.