Ruby ruby 调用 WebService 用的是 https 的链接,如何解决证书的问题

xiaohuihui · 2021年09月01日 · 最后由 xiaohuihui 回复于 2021年09月03日 · 570 次阅读

于公司用的是 ruby 1.8.7 的版本,现在要对接其他公司的 WebService,并且对方采用的是 https 协议,

require 'soap/wsdlDriver'
require 'soap/rpc/driver'
require 'soap/wsdlDriver'
require 'soap/mapping/wsdlencodedregistry'
require 'soap/mapping/mapping'
require 'soap/mapping/registry'

      wsdl = 'https://192.168.1.106:1234/services/WSInterface?wsdl'
    driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver

然后会报这样子的错误:

warning: peer certificate won't be verified in this SSL session
ignored attr: {http://schemas.xmlsoap.org/ws/2004/09/policy}PolicyURIs
ignored attr: {http://www.w3.org/2006/05/addressing/wsdl}Action
ignored element: {http://www.w3.org/2006/05/addressing/wsdl}UsingAddressing
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}binding
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}operation
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}body
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}fault
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}address
ignored element: {http://schemas.xmlsoap.org/ws/2004/09/policy}Policy
C:/Ruby187/lib/ruby/1.8/wsdl/soap/methodDefCreator.rb:158:in `documentdefinedtype': part: parameters cannot be resolved (RuntimeError)
        from C:/Ruby187/lib/ruby/1.8/wsdl/soap/methodDefCreator.rb:70:in `collect_documentparameter'
        from C:/Ruby187/lib/ruby/1.8/wsdl/soap/methodDefCreator.rb:68:in `each'
        from C:/Ruby187/lib/ruby/1.8/wsdl/soap/methodDefCreator.rb:68:in `collect_documentparameter'
        from C:/Ruby187/lib/ruby/1.8/soap/wsdlDriver.rb:132:in `create_param_def'
        from C:/Ruby187/lib/ruby/1.8/soap/wsdlDriver.rb:101:in `add_operation'
        from C:/Ruby187/lib/ruby/1.8/xsd/namedelements.rb:58:in `each'
        from C:/Ruby187/lib/ruby/1.8/xsd/namedelements.rb:57:in `each'
        from C:/Ruby187/lib/ruby/1.8/soap/wsdlDriver.rb:96:in `add_operation'
        from C:/Ruby187/lib/ruby/1.8/soap/wsdlDriver.rb:40:in `create_rpc_driver'
        from his_webservice.rb:38:in `get_dept_arr'
        from his_webservice.rb:48

如果采用 http 协议的话:

    qqcode = "15445600"
wsdl = 'http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl'
## 获得web对象
driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
### 调用对象的方法
ds = driver.qqCheckOnline(:qqCode=>qqcode)

这种调用是可以实际返回结果的 现在变为 https,不知道如何加入这个 ssl 认证,有没有高手指点一下,感谢

偏个题:ruby 1.8.7 2013 年就 EOL 了,这么老的版本楼主公司还不安排升级下,可能新版 ruby or gem 就没问题了~

https 也分很多版本 ssl1 ssl2 ssl3 tls1.0 tls1.1 tls1.2 tls1.3
现在主流的网站用 tls1.2 新潮一点的网站比如 ruby-china 用 tls1.3

@zhengpd 老项目啦,公司一直没有人手做这个事情,现在由于版本是遇到越来越多的问题啦

@tablecell 第一次搞这个,有点儿懵

解决这种问题是无底洞,如果可能尽快推动系统升级

xiaohuihui 回复

从 1.8 升级到 3.0 步子有点大,容易扯到蛋。这种情况,你可以用新版本起个本地代理 旧系统用 http 访问本地新版本代理,然后新版本用 https 转发到其他公司的 webservice,如果担心 rails 性能问题的话,可以用 sinatra

再部署一套系统,用最新的,内网请求数据?

@tablecell 为了省事,我放弃了 ruby,我准备用 python3.8 对接对方的 webservice😔

@zhengpd 谢谢啦,这个应该是 https 直接返回结果的,用 python 啦😂

@littlell 有时间了 就该升级啦

@Catherine 那样感觉复杂啦

需要 登录 后方可回复, 如果你还没有账号请 注册新账号