I would like to check if the URI will need SSL authentication:
url = URI.parse("http://www.google.com")
# [some code]
if url.instance_of? URI::HTTPS
http.use_ssl=true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
However, those few lines throw the following error..
/usr/lib/ruby/1.8/uri/common.rb:436:in `split': bad URI(is not URI?): HTTPS (URI::InvalidURIError)
from /usr/lib/ruby/1.8/uri/common.rb:485:in `parse'
from /usr/lib/ruby/1.8/uri/common.rb:608:in `URI'
from links.rb:18
Why is it happening?
>> uri = URI.parse("http://www.google.com")
=> #<URI::HTTP:0x1014ca458 URL:http://www.google.com>
>> uri.scheme
=> "http"
>> uri = URI.parse("https://mail.google.com")
=> #<URI::HTTPS:0x1014c2e60 URL:https://mail.google.com>
>> uri.scheme
=> "https"
So you could check uri's scheme against simple "https" string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With