gpt4 book ai didi

ruby - 在 Ruby 中使用 HTTPClient 重定向到非 https 资源错误

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

当我使用 content = client.get_content(lasturl) 时出现此错误:

/var/lib/gems/1.9.1/gems/httpclient-2.3.4.1/lib/httpclient.rb:664:in `default_redirect_uri_callback': redirecting to non-https resource (HTTPClient::BadResponseError)
from /var/lib/gems/1.9.1/gems/httpclient-2.3.4.1/lib/httpclient.rb:962:in `call'
from /var/lib/gems/1.9.1/gems/httpclient-2.3.4.1/lib/httpclient.rb:962:in `follow_redirect'
from /var/lib/gems/1.9.1/gems/httpclient-2.3.4.1/lib/httpclient.rb:594:in `get_content'
from he_sender.rb:332:in `<main>'

我想获取的 URL 是 https,我已经禁用了 SSL 检查:

client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE

我该如何解决这样的问题?谢谢。

最佳答案

https 重定向到 http 是不好的,HTTPClient 可以保护您免受这种情况的影响。

如果您真的想要允许并消除异常,您可以覆盖 redirect_uri_callback :

client.redirect_uri_callback = ->(uri, res) {
res.header['location'][0]
}

关于ruby - 在 Ruby 中使用 HTTPClient 重定向到非 https 资源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23429738/

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