RestClient :: Request.execute transfer hashset

I used the RestClient query as such:

response = RestClient.post server_url, post_params, accept: :json 

Which is working fine. But I need to increase the timeout since it does not end from time to time while the server is loading.

I researched and found that the only solution is to change the syntax to something like:

 response = RestClient::Request.execute(:method => :post, :url => server_url, post_params, :timeout => 9000000000) 

however, it seems that I cannot pass the hash of the parameter file ( 'post_params' ) as I could in the previous call. how can I write a request to include 'post_params' . This is a complex hashmap, so I can’t increase it or get rid of it.

Help is much appreciated.

+6
source share
2 answers

The data you send is called the payload, so you need to specify it as the payload:

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

Alternatively, you can use a shorter timeout, otherwise you are likely to get the argument Errno :: EINVAL: Invalid.

+11
source

the data you send is in the payload when we try to use rest_client.post or any method like get, put which rest_client do

 def self.post(url, payload, headers={}, &block) Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers, &block) end 

so what we want to accomplish

  response = RestClient.post api_url, {:file => file, :multipart => true }, { :params =>{:foo => 'foo'} #query params 

therefore, the execute command will take {:file => file, :multipart => true } as a payload and { :params =>{:foo => 'foo' } } as a header, so to transfer all this you need

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

it should do

+1
source

All Articles