1

我正在用 Ruby-on-Rails 编码

我想向另一个服务发送一个 http 请求,但不等待响应。

伪代码:

 def notification
     require 'net/http'

     ...
     # send net/http request
     Net::HTTP.post_form(url, params)

     render :text => "Rendered quickly as did not wait for response from POST"
 end

有什么方法可以发送 POST 请求而不是等待响应而只是快速呈现页面?

4

1 回答 1

1

你可以试试delay_job。它主要用于在后台运行进程。安装后delayed_job,您可以这样做。

   require 'net/http'

   def notification

     ...
     your_http_request  #calling method
     render :text => "Rendered quickly as did not wait for response from POST"
   end

   def your_http_request
     # send net/http request
     Net::HTTP.post_form(url, params)
     #do your stuff like where to save response
   end

   handle_asynchronously :your_http_request
于 2013-03-01T18:19:49.827 回答