如何使西纳特拉代码中POST请求?(How to make a POST request insid

2019-07-29 00:35发布

在一个形式点击一个按钮将发送POST请求到由下面的代码段来处理。

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

我怎样才能从Ruby代码内发送另一个POST请求到不同的网站?

Answer 1:

使用网:: HTTP从Ruby的标准库或HTTParty宝石。



文章来源: How to make a POST request inside Sinatra code?
标签: ruby sinatra