post_connection_check':主机名“ ip”与服务器证书不匹配(OpenSSL :: SSL :: SSLError)

时间:2019-04-10 06:59:18

标签: ruby openssl

我尝试使用REST方法连接到远程服务器,在ruby中,我遇到了

错误
/usr/lib/ruby/2.3.0/openssl/ssl.rb:315:in `post_connection_check': hostname "ip" does not match the server certificate (OpenSSL::SSL::SSLError)
        from /usr/lib/ruby/2.3.0/net/http.rb:944:in `connect'
        from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
        from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start'
        from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:715:in `transmit'
        from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:145:in `execute'
        from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:52:in `execute'
        from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient.rb:71:in `post'

此错误从下面的代码行

发生

require 'rest-client'

response        = RestClient.post(url, data, content_type: ctype)

我尝试从命令行使用openssl连接到服务器,如下所示 我能够连接到服务器

openssl s_client -connect ip:port 

由于我仅使用红宝石,如何解决此错误。 (不是导轨) 请帮我。预先感谢。

1 个答案:

答案 0 :(得分:0)

hostname "ip" does not match the server certificate (OpenSSL::SSL::SSLError)意味着服务器证书验证存在一些问题。

根据您的情况,可以忽略或不忽略它。如果您想忽略它(注意:不安全),请使用

response = RestClient.execute(method: :post, 
                              url: url, 
                              payload: data, 
                              verify_ssl: false, 
                              headers: { content_type: ctype })

请参见https://github.com/rest-client/rest-client/issues/288