Savon, Wasabi Error when connecting a Ruby script to a SOAP url

一个人想着一个人 提交于 2019-12-08 07:34:06

问题


Im trying to connect to a SOAP URL with a Ruby script.

I am following this Railscasts episode. I installed the savon gem(savon (2.4.0)).

Then in my ruby file I have this code:

 require 'savon'

 client = Savon.client(wsdl:"https://api.comscore.com/KeyMeasures.asmx?WSDL")
 response = client.call(:authenticate , message: { username:"xxxxx", password:"xxxxx"})

 puts "#{response.inspect}"

I know there is no issue with the url because I used SOAPUI and placed the WSDL URL there and I got back a response.

When I run the ruby file above I get the following exception:

  /Users/XXXX/.rvm/gems/ruby-2.0.0-p247/gems/wasabi-3.2.3/lib/wasabi/resolver.rb:44:in `load_from_remote': Error: 401 (Wasabi::Resolver::HTTPError)
from /Users/XXXXX/.rvm/gems/ruby-2.0.0-p247/gems/wasabi-3.2.3/lib/wasabi/resolver.rb:32:in `resolve'

After googling about I saw this post, which seems to suggest that I should install and require gem "httpclient" which I did and then tried again. No changes, Still getting the same error.

Can someone give me a hand as to how to proceed .....

Thanks


回答1:


I tried to access the WSDL you provided using curl from the commandline. I cannot access the WSDL b/c I'm not authorized. I guess that first you have to provide the credentials as part of your https request. That's why wasabifails. It cannot find the WSDL document.

According to the documentation that can be done by injecting the following code into your client creation:

client = Savon.client(wsdl: ...,
                      basic_auth: [ 'username', 'password' ],
                      log: true,
                      log_level: :debug,
                      pretty_print_xml: true)
client.call(...)


来源:https://stackoverflow.com/questions/22990936/savon-wasabi-error-when-connecting-a-ruby-script-to-a-soap-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!