1

我在 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(...“行不通。知道吗?

4

3 回答 3

3

我想你想做的是:

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 标头中。

于 2013-10-02T18:01:17.437 回答
0

您的最后一个代码块缺少"第 2 行的第 2 行,最后的 ``` 太多了。它应该看起来像:

client = Savon.client do
  wsdl "http://www.shab.ch:9191/soapserver?wsdl"
end
service = client.call(:get_authentication, {username: "myuser", password: "mypass"})

不触发任何语法错误。

于 2013-10-07T13:14:50.433 回答
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 函数之前进行的标头注入。

于 2013-10-07T13:52:27.707 回答