ruby - 在 Windows 7 上为 Ruby 打开 SSL 错误

标签 ruby windows ssl rubygems mechanize

我在 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/

相关文章:

windows - 如何从 CMD.exe 切换到 Powershell?

ruby-on-rails - Heroku 控制台中的预期 (200) <=> 实际 (401 未经授权)

ruby-on-rails - 如何修复 ruby​​ bundle 安装错误?

ruby-on-rails - 如何获得特定佣金任务的帮助?

c# - C#将Windows窗体应用程序添加到控制台应用程序

performance - 负载测试原始 ssl/tls

php - curl 错误 (60) SSL 证书 : unable to get local issuer certificate

Ruby - 昨天到某个时间的时间戳

ruby-on-rails - rspec 测试的 JSON 数据

node.js - 为什么 Node.js Scaling 可以在 Linux 上运行,但不能在 Windows 上运行?