gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:29:30 24 4
gpt4 key购买 nike

请求open-uri后,可以通过Kernel#open方便地从网络上下载和使用文件。但是,尝试使用 https 执行此操作会导致根证书错误,因为 ruby​​ 没有所有根证书。

这个可以解决like this ,但那是为了将 Net::HTTP 对象与 block 一起使用。

有没有一种优雅的方法来全局设置 Net::HTTP 库的 use_sslca_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

关于ruby - 通过 open-uri 优雅地将 Kernel#open 用于 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6158581/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com