Skip to content

Commit 7d8a059

Browse files
committed
add SSL verification example to readme
1 parent eea968f commit 7d8a059

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,23 @@ To reference the installed CA Bundle, you can use the built-in function:
2626
> Certifi.where
2727
=> #<Pathname:/home/hone/.gems/ruby/2.1.0/ruby-certifi-14.5.14/lib/certifi/vendor/cacert.pem>
2828

29+
You can use this with `net/http` to verify the SSL certificate:
30+
31+
```ruby
32+
require 'uri'
33+
require 'net/https'
34+
require 'certifi'
35+
36+
uri = URI.parse('https://httpbin.org/')
37+
http = Net::HTTP.new(uri.host, uri.port)
38+
http.use_ssl = true
39+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
40+
http.ca_file = Certifi.where
41+
http.start do
42+
http.request_get(uri.path) do |res|
43+
puts res.body
44+
end
45+
end
46+
```
47+
2948
Enjoy!

0 commit comments

Comments
 (0)