我正在尝试构建正确的 SOAP header :
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sen="https://webservices.averittexpress.com/SendWebImageService">
<soapenv:Header
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns:authnHeader
soapenv:mustUnderstand="0"
xmlns:ns="http://webservices.averittexpress.com/authn">
<Username>xxxxxxxx</Username> <Password>xxxxxxxx</Password>
</ns:authnHeader> </soapenv:Header>
这是我的 Savon 客户端调用,我使用的是版本 2:
client = Savon.client(
wsdl: api_url,
raise_errors: false,
convert_request_keys_to: :camelcase,
element_form_default: :qualified,
env_namespace: :soapenv,
soap_header: {'username' => username, 'password' => password }
)
我收到以下 SOAP 错误:
fault=>
{:faultcode=>"soapenv:Server",
:faultstring=>"java.lang.NullPointerException",
:detail=>nil}}
如何获取 sapoenv:mustUserstand="0"
行,它是什么?
另外,我很困惑如何设置 xmlns:ns="http://webservices.averittexpress.com/authn">
。
我几乎没有使用 SOAP 请求的经验,并且具有 Ruby/Rails RESTful 背景。任何帮助,将不胜感激。
最佳答案
Savon 使用 Gyoku将 SOAP header 和正文转换为 XML。
遵循此库约定,您的哈希需要如下所示:
soap_header = {
"ns:authnHeader" => {
"@soapenv:mustUnderstand" => 0,
"@xmlns:ns" => "http://webservices.averittexpress.com/authn",
"Username" => "x",
"Password" => "x"
}
}
Savon.client(:soap_header => soap_header)
关于ruby - 正确构造此 SOAP header 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14343188/