Ruby 1.9.3-p392 +中的SSL连接错误

时间:2013-04-11 10:16:27

标签: ruby ssl ruby-1.9.3 rest-client ruby-2.0

在Ruby 1.9.3-p385或更早版本中,我可以成功运行以下代码:

require 'uri'
require 'net/http'

uri = URI('https://secure.example.com')

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == 'https'

http.start do |h|
  h.request Net::HTTP::Get.new(uri.request_uri)
end

在Ruby 1.9.3-p392或更高版本中,我收到以下错误:

/Users/jason/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:799:in `connect': Connection reset by peer - SSL_connect (Errno::ECONNRESET)
    from /Users/jason/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:799:in `block in connect'
    from /Users/jason/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
    from /Users/jason/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
    from /Users/jason/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:799:in `connect'
    from /Users/jason/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
    from /Users/jason/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:744:in `start'
    from /Users/jason/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:557:in `start'
  • 我已在最新版本的rbenv
  • 下安装了两个版本的Ruby
  • 我正在运行OpenSSL 1.0.1e
  • 我正在运行OSX 10.8.3(最新版本)

Ruby 1.9.3p-385和1.9.3-p392之间处理SSL的方式有什么重大差异吗?

基本上,最终目标是使用SSL(https://secure.example.com)连接到某个API端点,而不从客户端传递任何SSL证书的详细信息。理想情况下,我将能够使用rest-client Gem实现此目的(这会抛出与上面代码相​​同的错误)。

1 个答案:

答案 0 :(得分:0)

尝试设置http.ssl_version =:SSLv3,可能是您的API使用的是其他SSL版本