I'm trying to access a QA environment website using Net::HTTP::Proxy to get the response.But I keep getting a SocketError whenever I try to connect. Please find the code snippet that I'm trying to use.
proxy_addr = "http://autoproxy1.qa.com"
proxy_class = Net::HTTP::Proxy(proxy_addr,80).start("mywebsite.com")
This is the Error I'm getting
SocketError: getaddrinfo: Name or service not known
from /site/ruby/ruby-1.9.1-4/lib/ruby/1.9.1/net/http.rb:581:in `initialize'
from /site/ruby/ruby-1.9.1-4/lib/ruby/1.9.1/net/http.rb:581:in `open'
from /site/ruby/ruby-1.9.1-4/lib/ruby/1.9.1/net/http.rb:581:in `block in connect'
from /site/ruby/ruby-1.9.1-4/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
from /site/ruby/ruby-1.9.1-4/lib/ruby/1.9.1/timeout.rb:82:in `timeout'
from /site/ruby/ruby-1.9.1-4/lib/ruby/1.9.1/net/http.rb:581:in `connect'
from /site/ruby/ruby-1.9.1-4/lib/ruby/1.9.1/net/http.rb:574:in `do_start'
from /site/ruby/ruby-1.9.1-4/lib/ruby/1.9.1/net/http.rb:569:in `start'
from /site/ruby/ruby-1.9.1-4/lib/ruby/1.9.1/net/http.rb:453:in `start'
from (irb):6
from /site/ruby/ruby-1.9.1-4/bin/irb:12:in `<main>'
I'm able to access the same website using Selenium by configuring the autoproxy settings of the browser. But I need to get the response of it through Net::HTTP. Please let me k开发者_如何学编程now if there is any other way of doing it.
try removing the http://
from your proxy address.
#!/usr/bin/ruby1.9.3
require 'net/http'
proxy_addr = '109.104.128.130'
proxy_port = 8741
Net::HTTP::Proxy(proxy_addr, proxy_port).start('www.templesec.org') {|http|}
Net::HTTP
accepts URI's for the start and get classes, so you could change your code to something like this:
require 'uri'
require 'net/http'
proxy_addr = "http://autoproxy1.qa.com"
proxy_port = 80
proxy_class = Net::HTTP::Proxy(proxy_addr, proxy_port).start(URI("mywebsite.com"))
精彩评论