为什么在尝试使用ROR通过Faraday gem与Salesforce rest API建立连接时会出现此错误?
Faraday::Error::ConnectionFailed:
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
答案 0 :(得分:1)
法拉第需要有效的根证书才能建立连接。
如果您使用的是Windows计算机,请按照以下说明安装证书:https://gist.github.com/867550
对于Mac,请执行以下操作:
sudo port install curl-ca-bundle
接下来,在您的法拉第请求中,请在您实际发送请求的位置上方包含此行(例如https.request_get('/foo')
):
https.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt'
这将告诉faraday用于在其请求中包含证书的http对象。如果您的系统发出错误,您可能必须根据文件在系统中的位置调整包含。
总而言之,您的请求看起来像这样:
require 'net/https'
https = Net::HTTP.new('encrypted.google.com', 443)
https.use_ssl = true
https.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt' if File.exists('/opt/local/share/curl/curl-ca-bundle.crt') # Mac OS X
https.request_get('/foo')