Ruby on rails RestClient::Request.execute传递hashset

Ruby on rails RestClient::Request.execute传递hashset,ruby-on-rails,rest-client,Ruby On Rails,Rest Client,我一直在使用RestClient请求: response = RestClient.post server_url, post_params, accept: :json 它一直运作良好。但是我需要增加超时时间,因为在服务器执行上传时,它不是时不时地完成的 我研究发现,唯一的解决方案是将语法更改为: response = RestClient::Request.execute(:method => :post, :url => server_url, post_params, :t

我一直在使用RestClient请求:

response = RestClient.post server_url, post_params, accept: :json
它一直运作良好。但是我需要增加超时时间,因为在服务器执行上传时,它不是时不时地完成的

我研究发现,唯一的解决方案是将语法更改为:

response = RestClient::Request.execute(:method => :post, :url => server_url, post_params, :timeout => 9000000000)
但是,我似乎无法像在上一次调用中那样传递参数的hashmap(
'post_params'
)。我应该如何编写请求,以便包含
'post_params'
。这是一个复杂的hashmap,所以我不能扩充它或去掉它


非常感谢您的帮助。

您发送的数据称为有效负载,因此您需要将其指定为有效负载:

response = RestClient::Request.execute(:method => :post, :url => server_url, :payload => post_params, :timeout => 9000000, :headers => {:accept => :json})

另外,您可能希望使用更短的超时时间,否则可能会得到一个Errno::EINVAL:无效参数。

当我们尝试使用rest\u client.post或任何方法(如get、put、do)时,您发送的数据在有效负载中

所以我们想要执行

 response = RestClient.post api_url,
             {:file => file, :multipart => true },
             { :params =>{:foo => 'foo'} #query params
因此,在execute命令中,将把
{:file=>file,:multipart=>true}
作为有效负载,把
{:params=>{:foo=>'foo'}}}
作为头so 谢谢你通过了所有这些考试

response= RestClient::Request.execute(:method => :post, 
                                     :url => api_url,
                                     :payload => {:file => file, :multipart => true },
                                     :headers => { :params =>{:foo => 'foo'}},
                                      :timeout => 90000000)
这应该可以

response= RestClient::Request.execute(:method => :post, 
                                     :url => api_url,
                                     :payload => {:file => file, :multipart => true },
                                     :headers => { :params =>{:foo => 'foo'}},
                                      :timeout => 90000000)