我尝试使用 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
如何解决此错误,因为我只使用红宝石。( 不是导轨 (请帮助我。提前谢谢。
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