0

I tried to connect to remote server using REST method, in ruby I'm getting error as

/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'

this error occurred from the below line of code


require 'rest-client'

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

I tried connecting to server using the openssl from command line as follows I was able to connect to the server

openssl s_client -connect ip:port 

How to solve this error as I am using ruby only. ( not rails ) please help me. Thanks in advance.

shivakumar
  • 47
  • 2
  • 5

1 Answers1

0

hostname "ip" does not match the server certificate (OpenSSL::SSL::SSLError) means that the server certificate validation has some issue.

Depending on your situation, it can be OK to ignore it or not. In case you want to ignore it (note: insecure), use

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

See https://github.com/rest-client/rest-client/issues/288

claasz
  • 2,059
  • 1
  • 14
  • 16