从Ruby执行HTTPS GET调用?

时间:2015-06-15 20:25:27

标签: ruby rest http ssl https

以下是我正在尝试运行的代码,对公司安全性进行审查:

require 'net/http'
require 'uri'

uri = URI.parse('https://<<the gitlab address>>')

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
#http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(uri.request_uri)

response = http.request(request)
response.body
response.status

这甚至是我从another question

获得的一段代码
require "net/http"

uri = URI.parse("https://api.twitter.com/1/statuses/user_timeline.json")
args = {include_entities: 0, include_rts: 0, screen_name: 'johndoe', count: 2, trim_user: 1}
uri.query = URI.encode_www_form(args)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri.request_uri)

response = http.request(request)
response.body

在这两种情况下,我在运行时都遇到同样的错误:

C:/Ruby22-x64/lib/ruby/2.2.0/net/http.rb:923:in `connect': SSL_connect returned=
1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (Open
SSL::SSL::SSLError)
        from C:/Ruby22-x64/lib/ruby/2.2.0/net/http.rb:923:in `block in connect'
        from C:/Ruby22-x64/lib/ruby/2.2.0/timeout.rb:74:in `timeout'
        from C:/Ruby22-x64/lib/ruby/2.2.0/net/http.rb:923:in `connect'
        from C:/Ruby22-x64/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
        from C:/Ruby22-x64/lib/ruby/2.2.0/net/http.rb:852:in `start'
        from C:/Ruby22-x64/lib/ruby/2.2.0/net/http.rb:1375:in `request'
        from findMonitorId.rb:11:in `<main>'

我很困惑,现在去哪里,任何帮助都将受到赞赏。

0 个答案:

没有答案