문제

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']
도움이 되었습니까?

해결책

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.

다른 팁

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top