我有这段代码:
client = Savon.client(wsdl: wsdl)
response = client.call(:post, message: {
login: {
userName: username,
password: password
},
data: {
parameters: {
key: "firstName",
value: "Joe"
}
})
这有效,但我需要发送多个参数。如果我有多个parameters: {mydata}
字段,则它不起作用,因为哈希必须具有唯一键...
如何让Savon发送多个参数字段?
答案 0 :(得分:0)
我仍然不知道正确的方法,但message
参数可以是XML字符串,所以我最终得到了以下解决方案:
client = Savon.client(wsdl: wsdl)
response = client.call(:post, message: build_xml)
def build_xml
"
#{login_xml}
<data>
<code>CUSTOMER_DETAILS</code>
" + test_data.map { |h| parameter_xml(h.first, h.last) }.join("") + "
</data>
"
end
def login_xml
"
<login>
<userName>#{@xml_username}</userName>
<password>#{@xml_password}</password>
</login>
"
end
def parameter_xml(key, val)
"
<parameters>
<key>#{key}</key>
<value>#{val}</value>
</parameters>
"
end