Place nested parameters (hash) using HTTPClient

I needed to have multi-page HTTP mail from one application to another, which included a file attachment and a hash of the attached parameters. I tried using HTTPClientone that worked for file attachments, however I could not get the options for sending the attached format.


data_params = Hash.new
data_params[:params] = Hash.new
data_params[:params][:f] = Hash.new
data_params[:params][:d] = Hash.new
data_params[:params][:d][:name] = "Mich"
data_params[:params][:d][:city] = "Ostin"
data_params[:params][:f][:event] = "Sundance"

http_client = HTTPClient.new
body = data_params[:params]
response = http_client.post('http://localhost:3030/receiver/receive_test_data/', body)

when the receiving application sees the parameters as {"d"=>"nameMichcityOstin","f"=>"eventSundance"}(with a hash collapsing into lines at a nested level)

, HTTP - . JSON, , , , , . , " " .

+3
2

Rails:

> {:a=>53,:b=>{:c=>7}}.to_query 
=> "a=53&b[c]=7" 

http://apidock.com/rails/ActiveSupport/CoreExtensions/Hash/to_query

+3

, HTTPClient , , , ,

data_params[:params]['d[name]'] = "Mich"
data_params[:params]['d[city]'] = "Ostin"

. data_params[:params] - - .

- , .

0

Source: https://habr.com/ru/post/1760122/


All Articles