How to make a POST request inside Sinatra code?

ruby, sinatra

Solution

Use Net::HTTP from the Ruby Standard Library or the HTTParty gem.

Problem

Clicking a button in a form will send a POST request to be handled by the following piece of code. ``` post '/register' do #send post request to http://www.randomsite.com #parse response #do something with it @user = User.first(:name => params['regUsername']) if @user == nil @user = User.create( :name => params['regUsername'], :pass => Password.create(params['regPassword']), :email => params['regEmail'], :created_date => Time.now ) redirect '/' else "User already exists." end end ``` How can I send another POST request to a different website from within the Ruby code?

Original source