发出HTTP请求时,我有一个服务,使一个HTTP请求,它看起来像这样:OpenSSL的错误在Ruby中
require 'net/http'
class SenderNameService
def get_names(id)
domain = "http://www.somedomain.com"
path = "/api/orchards/users/#{id}"
url = URI.parse(domain + path)
req = Net::HTTP::Get.new(url.to_s)
token = generate_token
req.add_field("Authorization", token)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
res = http.start do |http|
http.request(req)
end
if res.code == '200'
return JSON.parse(res.body)
else
raise StandardError, "Request for sender names failed"
end
end
private
def generate_token
#Some JWT token generating logic goes here.
end
end
当我提出一个要求,我得到这个错误:
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
from .rbenv/versions/2.3.3/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock'
这是怎么回事?那个错误是什么意思?
UPDATE:当我将http
更改为https
时,错误得到修复。到底是怎么回事?
目标是否有可能拥有SHA1 SSL证书? – whodini9