Search code examples
rubywindowshttpproxymechanize-ruby

Make ruby automacially find the values for the proxy/authentication settings for http?


I'm using the ruby gem Mechanize to access a website through a proxy and it's working find I'm just wondering if it's possible to have ruby automatically fill in my proxy settings.

require 'mechanize'

agent = Mechanize.new do|a|
  a.set_proxy('proxy', port, 'YOUR_USER_NAME', 'YOUR_PASS')
end

I know how to get the username and proxy but not the password as the proxy requires authentication.

ENV['username']
ENV['http_proxy']

Solution

  • You should have a variable HTTP_PROXY in your environment containing all you need, for instance :

    HTTP_PROXY = http://username:password@proxyserver.domain.com
    

    Then, you should have a method where you can pass this string, or if you don't, some parsing will do the trick.