gpt4 book ai didi

ruby-on-rails - ruby : http POST with nested params not working

转载 作者:可可西里 更新时间:2023-11-01 16:29:56 26 4
gpt4 key购买 nike

我正在尝试使用 POST 和嵌套参数进行 Http 基本身份验证。虽然外部参数工作正常(class.name - ActionController::Parameters),但嵌套参数是字符串(class.name - String)这是我的代码 ->

require 'net/http'

uri = URI('http://example.com/bulb/')
req = Net::HTTP::Post.new(uri)
req.basic_auth 'mytest@somesite.com', '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

我可以使用哪些其他库来使嵌套参数工作而无需手动转换它们。我看到 set_form_data 不适用于嵌套哈希

最佳答案

试试这个

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')

关于ruby-on-rails - ruby : http POST with nested params not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38746407/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com