2

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 know if there is any other way of doing it.

ruby tester
  • 21
  • 1
  • 3

3 Answers3

3

try removing the http:// from your proxy address.

Chuck Norris
  • 15,207
  • 15
  • 92
  • 123
hendrikswan
  • 2,263
  • 1
  • 20
  • 25
1
#!/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|}
iblue
  • 29,609
  • 19
  • 89
  • 128
0

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"))
Jeff Geisperger
  • 583
  • 4
  • 17