我在Savon v1中有这个代码:
client = Savon.client("http://www.server.com:9191/soapserver?wsdl")
service = client.request :get_authentication do
client.http.headers["username"] = "myuser"
client.http.headers["password"] = "mypass"
end
更新savon v2.3.0后,我无法重新翻译。它应该像
client = Savon.client do
wsdl "http://www.shab.ch:9191/soapserver?wsdl
end
service = client.call(:get_authentication, {username: "myuser", password: "mypass"})`
但是行service = client.call(...
“不起作用。有什么想法吗?
答案 0 :(得分:2)
我认为你想要做的是:
gem "savon"
require "savon", "~>2.0"
...
client = Savon.client(headers: { username: "user", password: "password"},
wsdl: "http://www.example.com/?wsdl",
log: true,
log_level: :debug,
pretty_print_xml: true
#, and more options here if necessary)
这会将键/值对注入http头。
答案 1 :(得分:0)
你的最后一个代码块在第2行缺少一个"
并且最后有一个“太多”。它应该看起来像:
client = Savon.client do
wsdl "http://www.shab.ch:9191/soapserver?wsdl"
end
service = client.call(:get_authentication, {username: "myuser", password: "mypass"})
不会触发任何语法错误。
答案 2 :(得分:0)
经过大量的试验和错误,这对我有用:
client = Savon.client( wsdl: "http://www.server.com:9191/soapserver?wsdl", <\br>
headers: {'username' => 'myuser', 'password' => 'mypass'} )
service = client.call(:get_authentication)
所以我在调用:get_authentication函数之前执行了头注入。