Mechanize with proxy servers

M

Mark

Hi all. I am relatively new to Ruby. I have been trying to get
Mechanize to work with a proxy server and I am not having much luck. I
have tried searching and worked on this for many hours without luck. I
am sure that I am missing something :(

I am simply trying to get Mechanize to work using a proxy server. I am
using Mechanize 0.4.3.

I added the following function (which I realize is not necessary) in
mechanize.rb:

# This should set up a proxy if the method is called
def set_proxy(addr,port,user=nil,pass=nil)
@proxy_addr, @proxy_port, @proxy_user, @proxy_pass = addr, port,
user, pass
end

I also updated the "fetch_page" function to be:

http = Net::HTTP::proxy(@proxy_addr, @proxy_port, @proxy_user,
@proxy_pass).new(uri.host, uri.port)

instead of

http = Net::HTTP.new(uri.host, uri.port)

I call the function via another file containing:

page = agent.set_proxy('X.X.X.X', 80) #proxy address removed
page = agent.get("http://192.168.1.100/")

This works, so long as I don't set a proxy server address and port.

I know that the proxy server is working because this:

# Example
proxy_class = Net::HTTP::proxy('X.X.X.X', 80) #proxy address removed

proxy_class.start('www.google.com') {|http|
# connecting proxy.foo.org:8080
}

returns a valid value.




Could someone please give me a hand? I would appreciate the help.

Thanks!

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top