您好我正在使用Savon访问某些Web服务。
我正在使用此代码:
client=Savon.client(
wsdl: "WebService.wsdl",
env_namespace: "S",
convert_request_keys_to: :camelcase
)
response=client.call(:send_doc) do
message(
Attr1: "123",
Attr2: "ABC")
)
如何将请求文本发送到服务器?
此致 FAK
答案 0 :(得分:2)
Savon 2提供Observer接口。您可以注册在发送请求之前收到通知的Observer
。该接口包含一个Builder
对象,您可以在其中找到请求的XML内容。 Builder#pretty()
格式化XML内容。
class Observer
def notify(_, builder, _, _)
puts builder.pretty
nil
end
end
Savon.observers << Observer.new
另外,您可以将log: true
添加到客户端配置中。它可以记录请求。
client = Savon.client(log: true, ...)
答案 1 :(得分:1)
对于Savon的稳定版本,这是不可能的。但是,您可以使用Savon的第3版获取请求(有关安装说明和更多详细信息,请参阅the Savon website)。网站示例:
client = Savon.new('http://example.com?wsdl')
operation = client.operation(service_name, port_name, operation_name)
operation.build # returns SOAP request
你也可以monkeypatch Savon方法或设置自定义调试器来获取当前Savon版本的信息。有关更多信息,请参阅这些StackOverflow答案: