Pregunta

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']
¿Fue útil?

Solución

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.

Otros consejos

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?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top