Ruby 使用OpenURI在https域上打开非HTTP代理URI
我支持一个代理,我必须获得一个HTTPS网页来收集一些信息,但OpenURI返回一个错误:“非HTTP代理URI” 这就是问题所在:Ruby 使用OpenURI在https域上打开非HTTP代理URI,ruby,https,proxy,nokogiri,open-uri,Ruby,Https,Proxy,Nokogiri,Open Uri,我支持一个代理,我必须获得一个HTTPS网页来收集一些信息,但OpenURI返回一个错误:“非HTTP代理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-prox
> 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$
代理没有登录名/密码
有什么想法吗?好的,我已经找到了获取页面的方法,但是我必须为net/https切换打开uri,而且,我设置了OpenSSL来验证\u NONE,因为它是一个自签名证书(公司服务器):
它看起来很难看,如果有人找到更好的方法,请编辑这篇文章,但到目前为止,它工作正常。检查这篇文章我以前检查过,但我使用的代理上没有身份验证;由于Jenkins服务器上的自签名证书无效,该Jenkins网页随后将出现问题,但我认为这不是open uri目前抱怨的问题,我正在积极寻找解决方案,这已经持续了数周:(
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
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