2

I am trying to do Http Basic Authentication with POST and nested parameters. While the outer parameters work fine (class.name - ActionController::Parameters) the nested parameters are string (class.name - String) Here is my code ->

require 'net/http'

uri = URI('http://example.com/bulb/')
req = Net::HTTP::Post.new(uri)
req.basic_auth '[email protected]', 'mypassword'

req.set_form_data('first_params' => 'a', 'seconnd_params'=>'b', 'netsed_params'=>{'first_netsed'=>'c', 'second_nested'=>'d'}, 'commit'=>'Create Bulb', 'action'=>'create', 'controller'=>'bulb')

res = Net::HTTP.start(uri.hostname, uri.port) do |http|
  http.request(req)
end

case res
when Net::HTTPSuccess, Net::HTTPRedirection
  # OK  
else
  #failed
end

What other library can I use to make the nested params work without having to manually convert them. I see that set_form_data doesn't work with nested hash

1 Answer 1

5

Try this

req.set_form_data('first_params' => 'a', 'second_params'=>'b', 'nested_params[first_nested]' => 'c', 'nested_params[second_nested]' => 'd'}, 'commit'=>'Create Bulb', 'action'=>'create', 'controller'=>'bulb')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.