通过open-uri优雅地将Kernel#open用于https

| 要求“ 0”后,您可以通过“ 1”从网上方便地下载和使用文件。但是,尝试使用https进行操作会导致根证书错误,因为ruby并没有所有的根证书。 可以这样解决,但这是使用带有块的
Net::HTTP
对象。 是否有一种优雅的方法可以全局地为
Net::HTTP
库设置
use_ssl
ca_file
,以便将其应用于我的整个应用程序以及类似
Kernel#open
的命令?     
已邀请:
        好了,几个小时后,我想到了这个:
require \'open-uri\'
require \'net/https\'

module Net
  class HTTP
    alias_method :original_use_ssl=, :use_ssl=
    def use_ssl=(flag)
      self.ca_file = \"/path/to/ca-bundle.crt\"
      self.original_use_ssl = flag
    end
  end
end
此处描述更多:https://gist.github.com/996510     

要回复问题请先登录注册