ssl connect在Rails上不起作用,但在独立的ruby脚本中工作

时间:2014-10-28 05:44:09

标签: ruby-on-rails ruby

我从Rails应用程序中的Service对象中提取代码。

我在Rails

下收到了错误#<OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A>

我认为该错误来自Rails应用设置,

因为我可以在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'

0 个答案:

没有答案