Search code examples
rubyhttpsproxynokogiriopen-uri

Opening a non-HTTP proxy URI on https domain using OpenURI


I'm behind a proxy and I must get an HTTPS webpage to collect some information, but OpenURI returns an error: "Non-HTTP proxy URI".

This is the issue:

> yadayada@ubuntu:~/Desktop/test/lib$ ruby JenkinsTest.rb 
/home/yadayada/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:257:in `open_http': Non-HTTP proxy URI: https://web-proxy.yadayada:8088 (RuntimeError)
from /home/yadayada/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:736:in `buffer_open'
from /home/yadayada/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:211:in `block in open_loop'
from /home/yadayada/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:209:in `catch'
from /home/yadayada/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:209:in `open_loop'
from /home/yadayada/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:150:in `open_uri'
from /home/yadayada/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:716:in `open'
from /home/yadayada/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:34:in `open'
from JenkinsTest.rb:6:in `<main>'
yadayada@ubuntu:~/Desktop/test/lib$ 

This is the code I'm running:

  1 require 'rubygems'
  2 require 'nokogiri'
  3 require 'open-uri'
  4 
  5 # Request the Jenkins webpage
  6 @jenkinsWebPage = Nokogiri::HTML(open("https://yadayad.yada.yada.com:8443"))
  7 
  8 # Prints the received page
  9 puts @jenkinsWebPage 

The proxy has no login/password.

Any ideas?


Solution

  • Okay, so I've found out how to get the page, but I had to switch open-uri for net/https, also, I set OpenSSL to VERIFY_NONE, since it's a self signed certificate (company server):

    require 'rubygems'
    require 'nokogiri'
    require 'net/https'
    require 'openssl'
    
    class JenkinsTest
        # Request the Jenkins webpage
        def request_jenkins_webpage
            uri = URI.parse("https://https://yadayad.yada.yada.com:8443")
            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)
            @@page = Nokogiri::HTML(response.body)
        end
    
        def print_jenkins_webpage
            puts @@page
        end
    end
    

    It looks ugly, if anybody finds out a better way to put this, please edit this post, but as of now, it's working fine.