如何在 Ruby 中将数组作为参数传递给 SOAP

编程入门 行业动态 更新时间:2024-10-23 21:27:20
本文介绍了如何在 Ruby 中将数组作为参数传递给 SOAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

目前我正在使用 Savon 在 ruby​​ 中使用 WebService.它工作得很好,但我很难传递参数SOAP 数组类型的参数.以下代码无法正常工作:

Currently I'm using Savon to work with WebService in ruby. It works pretty well but I have difficulty to pass parameter for argument of SOAP array type. Following code doesn't work properly:

ids = [0,1,2] client.do_get_items { |soap| soap.body = { 'item-list' => ids }

如果您能解决我的问题或提出替代方案,我将不胜感激ruby&soap 库

I would appreciate if you can solve my problem or propose an alternative library for ruby&soap

推荐答案

我只是偶然发现了同样的问题,对我有用的临时解决方法如下:

I just stumbled on the same problem and the temporary workaround that worked for me is as follows:

ids = [0,1,2] client.do_get_items { |soap| soap.body = { 'item-list' => { 'item1' => 0, 'item2' => 1, 'item3' => 2 } }

名称item1"、item2"根本不重要.

The names "item1", "item2" shouldn't matter at all.

我使用以下辅助方法将常规数组转换为 SOAP 混乱:

I use the following helper method to convert regular arrays into SOAP mess:

def soap_array(array) returning({}) do |hash| array.each_with_index do |e, i| hash["item-#{i}"] = e end end end

更多推荐

如何在 Ruby 中将数组作为参数传递给 SOAP

本文发布于:2023-11-23 19:43:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622657.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   中将   参数   如何在   SOAP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!