我在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请求而不是等待响应而只是快速呈现页面?
答案 0 :(得分:1)
您可以尝试delayed_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