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?
Use Net::HTTP from the Ruby Standard Library or the HTTParty gem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With