开发者

Savon: How can I specify a custom XML in a hash body for a SOAP request?

开发者 https://www.devze.com 2023-03-17 00:37 出处:网络
In a SOAP Request, I need to specify repeated keys with different values like this: soap.body = {:query => {

In a SOAP Request, I need to specify repeated keys with different values like this:

soap.body = {:query => {
    :fields => {
        :string => 'Email',
        :string => 'FirstName',
        :string => 'LastName'
    }
}

With this hash, the request will be formed 开发者_JAVA百科with:

<query><fields><string>LastName</string></fields></query>

The last :string pair. So if I put:

soap.body = {:query => {
    :fields => "<string>Email</string>FirstName<string></string>LastName<string></string>"
}

This will result in:

<fields>&lt;string&gt;Email&lt;/string&gt;&lt;string&gt;FirstName&lt;/string&gt;&lt;string&gt;LastName&lt;/string&gt;</fields>

Is there a way to get this in a hash?:

<query><fields><string>Email</string><string>FirstName</string><string>LastName</string></fields></query>

Note: I'm using Ruby 1.8.7.


Your first code cannot work and it's not Savon's fault, repeated keys in a hash are simply overriden. Did you try with an array?

soap.body = {
  :query => {
    :fields => {:string => ['Email', 'FirstName', 'LastName'],
  }
}

Check also this: https://github.com/rubiii/savon/issues/45

0

精彩评论

暂无评论...
验证码 换一张
取 消