2011-05-27 12 views
1

在要求open-uri之後,可以通過Kernel#open方便地下載和使用網絡上的文件。但是,嘗試使用https執行此操作會導致發生根證書錯誤,因爲ruby沒有所有的根證書。優雅地使用Kernel#open for open via uri

這可以解決like this,但這是一個塊使用Net::HTTP對象。

有一種優雅的方式來設置爲Net::HTTPuse_sslca_file全球範圍內,使之適用於我的整個應用程序和命令一樣Kernel#open

回答

3

好了,幾個小時後,我想出了這一點:

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

+0

我想補充一點,這個工作作爲一種解決方案,我得到CarrierWave的remote_url功能(您可以通過https通過遠程URL添加附件)謝謝! https://groups.google.com/forum/?fromgroups=#!topic/carrierwave/HQxayNjVAs4 – 2013-02-19 20:12:12