Hi ! I'm trying to connect to an https URL, but it seems it doesn't work. Has anyone successfully connected from Ruby to an HTTPS server ? Thanks !
on 2006-03-24 19:10
on 2006-03-24 19:21
yes it does. require 'net/http' require 'net/https' h = Net::HTTP.new("www.google.com", 443) h.use_ssl = true resp, data = h.get("/", nil ) @message = resp.message resp.code Hope that helps.
on 2006-03-24 21:17
Hello Brian ! 2006/3/24, Brian H. <email@example.com>: > require 'net/http' > require 'net/https' > > h = Net::HTTP.new("www.google.com", 443) > h.use_ssl = true > resp, data = h.get("/", nil ) > @message = resp.message > resp.code Works like a charm. Thanks !
on 2006-03-24 23:14
A bit off topic, but why use Net::HTTP if you don't have to. open-uri (in the standard library) is SOOOO much simpler: require 'open-uri' open("https://www.google.com") do |f| @message = f.gets(nil) f.status # array of messages but same effect end
on 2006-03-24 23:27
Well, let's see... irb(main):030:0> require 'open-uri' => false irb(main):031:0> irb(main):032:0* open("https://www.google.com") do |f| irb(main):033:1* @message = f.gets(nil) irb(main):034:1> f.status # array of messages but same effect irb(main):035:1> end OpenSSL::SSL::SSLError: certificate verify failed from c:/ruby/lib/ruby/1.8/net/http.rb:588:in `connect' from c:/ruby/lib/ruby/1.8/net/http.rb:588:in `connect' from c:/ruby/lib/ruby/1.8/net/http.rb:555:in `do_start' from c:/ruby/lib/ruby/1.8/net/http.rb:544:in `start' from c:/ruby/lib/ruby/1.8/open-uri.rb:245:in `open_http' from c:/ruby/lib/ruby/1.8/open-uri.rb:629:in `buffer_open' from c:/ruby/lib/ruby/1.8/open-uri.rb:167:in `open_loop' from c:/ruby/lib/ruby/1.8/open-uri.rb:165:in `open_loop' from c:/ruby/lib/ruby/1.8/open-uri.rb:135:in `open_uri' from c:/ruby/lib/ruby/1.8/open-uri.rb:531:in `open' from c:/ruby/lib/ruby/1.8/open-uri.rb:86:in `open' from (irb):32 That's why I don't use it! :) Seriously, net/https warns of certificate issues but does not throw exceptions. Not every site has valid certificates and so I tend to always go the somewhat longer route.
on 2006-03-24 23:34
Good point, good point. I probably would have seen that if OpenSSL actually worked on Windows w/ 1.8.4 (or at least, with my one-click installer's version of 1.8.4).
on 2006-03-25 00:44
On 3/24/06, Justin B. <firstname.lastname@example.org> wrote: > > Good point, good point. I probably would have seen that if OpenSSL > actually worked on Windows w/ 1.8.4 (or at least, with my one-click > installer's version of 1.8.4). > Have you submitted this as a bug to the instant rails team? The project site can be found at http://rubyforge.org/projects/instantrails . I'd highly suggest you submit any problems like this that you run into so that the team can get them fixed for the next release.
on 2006-03-25 01:24
Done (its actually the one-click installer). Thanks for the reminder.
on 2006-03-25 08:59
When I try it I get: ArgumentError: open-uri doesn't support https. from c:/ruby/lib/ruby/1.8/open-uri.rb:583:in `proxy_open' from c:/ruby/lib/ruby/1.8/open-uri.rb:525:in `direct_open' from c:/ruby/lib/ruby/1.8/open-uri.rb:169:in `open_loop' from c:/ruby/lib/ruby/1.8/open-uri.rb:164:in `catch' from c:/ruby/lib/ruby/1.8/open-uri.rb:164:in `open_loop' from c:/ruby/lib/ruby/1.8/open-uri.rb:134:in `open_uri' from c:/ruby/lib/ruby/1.8/open-uri.rb:424:in `open' from c:/ruby/lib/ruby/1.8/open-uri.rb:85:in `open' from (irb):10 But Net::HTTP worked fine. b (windoze w/ ruby 1.8.2 (2004-12-25) [i386-mswin32])