在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'
Ruby 1.9.3p-385和1.9.3-p392之间处理SSL的方式有什么重大差异吗?
基本上,最终目标是使用SSL(https://secure.example.com)连接到某个API端点,而不从客户端传递任何SSL证书的详细信息。理想情况下,我将能够使用rest-client Gem实现此目的(这会抛出与上面代码相同的错误)。
答案 0 :(得分:0)
尝试设置http.ssl_version =:SSLv3,可能是您的API使用的是其他SSL版本