1. Computing

Using an HTTP Proxy

By

Mechanize can be configured to use HTTP proxies. Some network configurations require you to use HTTP proxies to make connections outside the network, and there are various proxies one might want to run on localhost for debugging or inspection purposes.

To configure a proxy, use the Mechanize#set_proxy method. It takes four parameters, the proxy host, port and an optional user and password. In this example, a proxy at localhost on port 10000 is configured in the block passed to Mechanize#new.


agent = Mechanize.new do|a|
  a.set_proxy('localhost', 10000, 'user', 'pass')
  a.user_agent_alias = "Windows IE 6"
end
  1. About.com
  2. Computing
  3. Ruby
  4. Tutorials
  5. The Mechanize 2.0 Handbook
  6. Using an HTTP Proxy

©2014 About.com. All rights reserved.