Ssl connect doesn't work with Rails but does work in standalone ruby โ€‹โ€‹script

I am retrieving code from a Service object in my Rails application.

I got an error #<OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A>

under Rails

I think the error is related to setting up the Rails application,

Because I can run this code completely outside of Rails.

require 'rest_client'

module Server

  def rest_query(server_url, header, content)
    begin
      resp = RestClient.post(server_url, content, header)
      return { code: resp.code,
               header: resp.raw_headers,
               body: resp.body }
    rescue Exception => e
      return { code: @@unknown_error_code,
               header: nil,
               body: @@unknown_error_msg }
    end
  end
end
class Portal
  include Server
  def initialize
    @server_url = "https://154.210.16.60:443/"
    @header = {
      "Accept" => " application/json",
      "Content-Type" => "application/json"
    }
  end

  def query(conn_type=:rest, raw_content='', session_id=nil)
    header = @header.clone
    header["Cookie"]="connect.sid=#{session_id}" if session_id
    content = raw_content.squeeze(' ')
    if :rest == conn_type
      return rest_query(@server_url, header, content)
    elsif :curl == conn_type
      return curl_query(@server_url, header, content)
    end
  end
end

raw_content = '{ "ServiceID": "Login", "UserID": "anny.ping@yahoo.com", "Password": "98765413df321" }'
portal = Portal.new

      

Gemfile

gem 'rails', '4.1.6'
gem 'curb'
gem 'rest_client'
gem 'httpclient'

      

+3


source to share





All Articles