问题
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 wasabi
fails. 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