gpt4 book ai didi

ruby - RestClient.get 返回证书验证失败

转载 作者:数据小太阳 更新时间:2023-10-29 07:15:02 28 4
gpt4 key购买 nike

我正在尝试使用 RestClient 和 Ruby v. 2.2.1 访问内部测试 API 服务器。

这基本上是代码:

url = "https://10.10.0.10/thing/i/want/to/get"
header = {
:content_type => "application/json",
:"x-auth-token" => "testingtoken"
}
response = RestClient.get url, header

这是我收到的失败消息:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (RestClient::SSLCertificateNotVerified)

如果我没看错的话,Ruby 似乎无法接受 SSL 安全证书。此调用在 Chrome 应用程序 Postman 中有效,但为了使其正常工作,我必须在 Chrome 本身中点击 URL 并接受连接不安全(但无论如何继续),然后它将在 postman 中工作。

有没有办法在 Ruby 中忽略证书失败并继续进行?

最佳答案

尝试使用 #execute(&block) 并将 verify_ssl 设置为 false

:verify_ssl enable ssl verification, possible values are constants from OpenSSL::SSL::VERIFY_*, defaults to OpenSSL::SSL::VERIFY_PEER

url = "https://10.10.0.10/thing/i/want/to/get"
headers = {
:content_type => "application/json",
:"x-auth-token" => "testingtoken"
}

RestClient::Request.execute(
:url => url,
:method => :get,
:headers => headers,
:verify_ssl => false
)

参见:http://www.rubydoc.info/github/rest-client/rest-client/RestClient/Request#execute-instance_method


RVM

RVM 用户的附加解决方案来自:https://toadle.me/2015/04/16/fixing-failing-ssl-verification-with-rvm.html

This discussion on Github finally gave the solution: Somehow RVM comes with a precompiled version of ruby that is statically linked against an openssl that looks into /etc/openssl for it's certificates.

What you wanna do is NOT TO USE any of the precompiled rubies and rather have ruby compiled on your local machine, like so: rvm install 2.2.0 --disable-binary

关于ruby - RestClient.get 返回证书验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38255071/

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