使用 Savon 2 发送原始 XML [英] Sending raw XML using Savon 2
问题描述
我正在尝试使用 Savon 向网络服务发送请求.我使用的服务需要嵌套的命名空间,我还没有想出如何在请求时提供它们.
I'm trying to use Savon to send requests to a webservice. The service I'm consuming requires nested namespaces, and I haven't figured out yet how to provide them on a request.
我尝试手工制作请求(实际上是使用 nokogiri)并发送生成的 xml:
I've tried to craft the request by hand (with nokogiri, actually) and send the resulting xml:
client.call(:some_op, :message=>{:"op"=>"<elem/>"})
但是 savon 对字符串进行转义并发送 <elem/>
But savon escapes the string and sends <elem/>
如何在不转义的情况下发送原始 xml?
How can I send raw xml without escaping?
推荐答案
调用应如下所示:
client.call(:some_op, xml: "<elem />")
或者,如果您只想设置一个或多个命名空间,请按如下方式创建一个客户端(不带 WSDL):
Or if you just want to set one or multiple namespaces then create a client as follows (without WSDL):
client = Savon.client(
:endpoint => 'http://www.example.com',
:namespace => 'urn:core.example.com',
:namespaces => { 'ns1' => 'http://v1.example.com',
'ns2' => 'http://v2.example.com' },
:log => true,
:log_level => :debug,
:pretty_print_xml => true
)
命名空间是一个 Hash
参数.
The namespaces are a Hash
parameter.
这篇关于使用 Savon 2 发送原始 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!