0

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']
Lifeweaver
  • 986
  • 8
  • 29

2 Answers2

0

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.

Intrepidd
  • 19,772
  • 6
  • 55
  • 63
  • Right now I just have my proxy/port in the 'HTTP_PROXY' and was hoping there was some other way than modify it. It would work on my pc but if I used the script on another s they might not have the 'HTTP_PROXY'. – Lifeweaver Mar 14 '13 at 18:49
  • You get the gold since it actually answers my question even if my solution was something else. – Lifeweaver Mar 18 '13 at 11:35
0

Turns out all I needed was:

require 'mechanize'

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

I guess I just assumed that I would need the password but it looks like you only need your username.! Perhaps mechanize uses NTLM or some such?

Lifeweaver
  • 986
  • 8
  • 29