使用 OpenURI 在 https 域上打开一个非 HTTP 代理 URI

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

我在代理后面,我必须获得一个 HTTPS 网页来收集一些信息,但是 OpenURI returns 一个错误:"Non-HTTP proxy URI".

问题是:

> 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$ 

这是我的代码 运行:

  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 

代理没有login/password。

有什么想法吗?

好的,所以我找到了如何获取页面,但我不得不为 net/https 切换 open-uri,另外,我将 OpenSSL 设置为 VERIFY_NONE,因为它是一个自我签名证书(公司服务器):

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

它看起来很难看,如果有人找到更好的方式来放置它,请编辑它 post,但截至目前,它工作正常。