發出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