如何在rails中增加HTTParty post方法的超时?

Gop*_*aju 2 ruby ruby-on-rails httparty

我在rails中有一个方法可以将发布请求发送到第三方API.代码类似于以下内容:

data = HTTParty.post("url",
  :headers=> {'Content-Type' => 'application/json'},
  :body=> { update => true, first_name => "name" }
)
Run Code Online (Sandbox Code Playgroud)

这样,在一分钟之后,该过程终止,并出现以下错误.

<Net::HTTPGatewayTimeOut 504 GATEWAY_TIMEOUT readbody=true>
Run Code Online (Sandbox Code Playgroud)

saw*_*awa 7

设置默认值:

module HTTParty
  default_timeout your_preferred_timeout
end
Run Code Online (Sandbox Code Playgroud)

或者单独设置:

data = HTTParty.post("url",
  headers: {"Content-Type" => "application/json"},
  body: {update => true, first_name => "name"},
  timeout: your_preferred_timeout
)
Run Code Online (Sandbox Code Playgroud)