在 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 来实现这一点(这会引发与上面的代码相同的错误)。