加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 03:25:02 所属栏目:百科 来源:网络整理
导读:我正在使用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,head
我正在使用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本身的网址并接受连接不安全(但仍然继续),然后它将在邮递员中工作.

有没有办法忽略证书失败并继续在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 07002 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读