【问题标题】:post_connection_check': hostname "ip" does not match the server certificate (OpenSSL::SSL::SSLError)post_connection_check':主机名“ip”与服务器证书不匹配(OpenSSL::SSL::SSLError)
【发布时间】:2019-04-10 06:59:18
【问题描述】:

我尝试使用 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 

如何解决这个错误,因为我只使用 ruby​​。 (不是铁轨) 请帮我。提前致谢。

【问题讨论】:

  • 该网址是“https”网址吗?
  • 是的,这是由以下代码行决定的。方案 = self.ssl ? "https" : "http" url = "#{scheme}://#{host}:#{port}/#{uri}"

标签: ruby openssl


【解决方案1】:

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

【讨论】:

  • 我使用了“reposne = RestClient::Request.execute”,它起作用了。谢谢。
猜你喜欢
  • 1970-01-01
  • 2015-06-27
  • 2018-09-28
  • 2011-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-17
  • 1970-01-01
相关资源
最近更新 更多