Rest-Client Ruby Gem 标头
我正在尝试使用rest-client gem 来发布某些内容,但由于某种原因,我不断收到内部服务器错误。我在 Chrome 上使用了 Simple REST Client,并且得到了相同的错误,除非我发送以下标头:
Content-Type: application/x-www-form-urlencoded
因此,我尝试通过 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'
有人可以告诉我我做错了什么吗?已经搜索了一些指示如何设置标题的文档,但似乎没有任何效果。
I'm attempting to use the rest-client gem to post something, but for some reason, I keep getting Internal Server Error. I used Simple REST Client on Chrome, and got the same error unless I sent the following header:
Content-Type: application/x-www-form-urlencoded
So I'm trying to send that header with the post request, but for some reason, it's still not working. Here is what I tried:
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'
Can someone tell me what I'm doing wrong? Have searched all over for some docs which indicate how to set header, but nothing seems to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了这样的方法并且工作得很好:
看起来必须像使用普通参数一样传递多部分。第二个参数将简单地添加到标题中。
希望这有帮助
I tried something like this and worked fine:
Looks like multipart must be passed as you do with normal parameters. The second arguments will be simply added to the headers.
Hope this helps