1

尝试使用 Savon 2.1.0 为身份验证构建自定义标头时出现异常,这是重现该问题的示例代码,我将不胜感激有关此主题的任何帮助。

require 'open-uri'
require 'savon'

headers = {
  'IvansWSAuthentication' => {
    'User' => 'my_user',
    'Password' => 'my_pass',
    'ClientId' => 'my_client_id'
  }
}

x12 = 'test'

client = Savon.client(
  wsdl: 'https://limeservices.ivans.com/EligibilityOne.asmx?WSDL',
  headers: headers
)

request_params = {
  form270: x12
}

response = client.call(:send_commercial_eligibility_form_request, message: request_params)

这是一个例外:

1.9.3-p392 :023 >   response = client.call(:send_commercial_eligibility_form_request, message: request_params)
D, [2013-03-05T23:02:30.647097 #11590] DEBUG -- : HTTPI GET request to limeservices.ivans.com (net_http)
I, [2013-03-05T23:02:31.600016 #11590]  INFO -- : SOAP request: https://limeservices.ivans.com/EligibilityOne.asmx
I, [2013-03-05T23:02:31.600157 #11590]  INFO -- : IvansWSAuthentication: {"User"=>"my_user", "Password"=>"my_pass", "ClientId"=>"my_client_id"}, SOAPAction: "http://tempuri.org/SendCommercialEligibilityFormRequest", Content-Type: text/xml;charset=UTF-8, Content-Length: 389
D, [2013-03-05T23:02:31.600206 #11590] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://tempuri.org/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><tns:SendCommercialEligibilityFormRequest><tns:form270>test</tns:form270></tns:SendCommercialEligibilityFormRequest></env:Body></env:Envelope>
D, [2013-03-05T23:02:31.600474 #11590] DEBUG -- : HTTPI POST request to limeservices.ivans.com (net_http)
NoMethodError: undefined method `strip' for #<Hash:0x007fb044365a50>
    from /Users/rorra/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/http.rb:1435:in `block in initialize_http_header'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/utils.rb:451:in `block in each'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/utils.rb:450:in `each'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/utils.rb:450:in `each'
    from /Users/rorra/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/http.rb:1433:in `initialize_http_header'
    from /Users/rorra/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/http.rb:1862:in `initialize'
    from /Users/rorra/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/http.rb:2093:in `initialize'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/httpi-2.0.2/lib/httpi/adapter/net_http.rb:87:in `new'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/httpi-2.0.2/lib/httpi/adapter/net_http.rb:87:in `request_client'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/httpi-2.0.2/lib/httpi/adapter/net_http.rb:55:in `block in do_request'
    from /Users/rorra/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/http.rb:745:in `start'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/httpi-2.0.2/lib/httpi/adapter/net_http.rb:54:in `do_request'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/httpi-2.0.2/lib/httpi/adapter/net_http.rb:31:in `request'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/httpi-2.0.2/lib/httpi.rb:137:in `request'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/httpi-2.0.2/lib/httpi.rb:109:in `post'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/savon-2.1.0/lib/savon/operation.rb:59:in `call!'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/savon-2.1.0/lib/savon/operation.rb:48:in `call'
    from /Users/rorra/.rvm/gems/ruby-1.9.3-p392/gems/savon-2.1.0/lib/savon/client.rb:38:in `call'
    from (irb):23
    from /Users/rorra/.rvm/rubies/ruby-1.9.3-p392/bin/irb:16:in `<main>'1.9.3-p392 :024 > 
4

1 回答 1

0

好的,问题是通过在 Savon 2.1.0 上设置参数“headers”,我正在做的是设置 HTTP 请求的标头,并且 HTTP 请求参数应该是一个键:String,因为 ruby​​ HTTP 库对包含在 Header 中的每个哈希值调用strip ,它会引发异常。

我最初的想法是为身份验证设置自定义soap标头,所以我所要做的就是:

client = Savon.client(
  wsdl: 'https://limeservices.ivans.com/EligibilityOne.asmx?WSDL',
  soap_header: headers
)
于 2013-03-06T07:21:10.740 回答