Rest-Client Ruby Gem Headers

thi*_*ure 4 ruby ruby-on-rails rest-client http-headers

我正在尝试使用rest-client gem发布一些东西,但由于某种原因,我不断收到内部服务器错误.我在Chrome上使用了Simple REST Client,除非我发送了以下标题,否则会出现同样的错误:

Content-Type: application/x-www-form-urlencoded
Run Code Online (Sandbox Code Playgroud)

所以我正在尝试使用post请求发送该标头,但由于某种原因,它仍然无法正常工作.这是我尝试过的:

RestClient.post "server", :content_type=>"Content-Type: application/x-www-form-urlencoded",:name=> 'Test', :message_type=> 'Request', :version=> '2.0'
RestClient.post "server", {:content_type=> "Content-Type: application/x-www-form-urlencoded"},:name=> 'Test', :message_type=> 'Request', :version=> '2.0'
RestClient.post "server", {"Content-Type" =>"Content-Type: application/x-www-form-urlencoded"},:name=> 'Test', :message_type=> 'Request', :version=> '2.0'
RestClient.post "server", :header => {:content_type=>: "Content-Type: application/x-www-form-urlencoded"},:name=> 'Test', :message_type=> 'Request', :version=> '2.0'
Run Code Online (Sandbox Code Playgroud)

有人能告诉我我做错了什么吗?已搜索过一些指示如何设置标题的文档,但似乎没有任何效果.

And*_*ghi 5

我尝试过类似的东西并且运行良好:

options[:multipart] = true
# more options

resource = RestClient::Resource.new uri, options[:username], options[:password]
resource.post options do |response, request, result|

..............

end
Run Code Online (Sandbox Code Playgroud)

看起来像必须像使用普通参数一样传递multipart.第二个参数将简单地添加到标题中.

希望这可以帮助

resource.post {params and request}, {custom headers here} do.... 
...
Run Code Online (Sandbox Code Playgroud)