我在 Windows 7 普通操作系统上运行。
Ruby、SSL 和 Windows 互不兼容,因此像这样的简单命令对我不起作用,这让我很头疼。我试过获取 RVM,更新我的环境变量,几乎所有的事情。
我不知道解决方案是什么。是否有为 Ruby 1.9.3 安装 OpenSSL gem 的解决方案?
require 'mechanize'
agent = Mechanize.new
page = agent.get('https://any-ssl-site-here.com')
puts page
最佳答案
因此,无论何时您尝试使用库访问 Windows 上的 https
url,它们基本上都会失败,因为 OpenSSL 不知道在哪里寻找 ca_file
。
修复非常简单,获取一个 CA 证书包(我最喜欢的是 cURL's CA Bundle)并将您要使用的任何库指向它。
在 mechanize
的情况下,他们使用 #ca_file
instance method 来实现.
换句话说,将您的代码更改为:
require 'mechanize'
agent = Mechanize.new
agent.ca_file = "path/to/ca_bundle.crt"
page = agent.get('https://any-ssl-site-here.com')
puts page
另外,查看 Luis Lavena's execellent answer to a similar question .
关于ruby - 在 Windows 7 上为 Ruby 打开 SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31867930/