1

我正在尝试使用 Savon 将 API Key 元素添加到 SOAP 标头,但正在打一场失败的战斗。我对 Ruby 还很陌生,我所知道的很少是自学的。根据他们的 API 文档,这是我需要添加的内容:此 ProductServe 函数将返回(SOAP-Header)身份验证元素,并且必须与每个请求一起发送。

参数

Required  Name     Type    Description                              Min Occurs Max Occurs
No        sToken   string  Unique token to identify visitor.        0          1
Yes       sApiKey  string  User specific key to authenticate user.  1          1

http://wiki.affiliatewindow.com/index.php/UserAuthentication

我还没有找到任何类似于我想做的事情,这是我尝试过的代码:

endpoint = "http://v3.core.com.productserve.com/ProductServeService.wsdl"
client = Savon.client

response = client.request :urn, "getCategory" do
  soap.endpoint = endpoint
  soap.header = {
    "urn:sApiKey" => "xxxx"
  }
end

任何帮助将不胜感激!

4

1 回答 1

1

看起来您需要配置您的 Savon 客户端:

client = Savon::Client.new do
  wsdl.document = endpoint
  wsdl.element_form_default = :unqualified
end

我进行了这些更改,您的其余代码返回了有效的 SOAP 响应。

无耻地抄袭了这个问题

于 2012-12-04T21:11:00.410 回答