How to make a POST request inside Sinatra code?

走远了吗. 提交于 2019-12-21 12:37:08

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/10184737/how-to-make-a-post-request-inside-sinatra-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!