Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Mechanize with proxy servers
Mark
5/11/2006 12:13:00 AM
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....
)
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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Mechanize with proxy servers
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password