Skip to content

Instantly share code, notes, and snippets.

@emergent
Created October 30, 2012 23:47
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save emergent/3983870 to your computer and use it in GitHub Desktop.
Save emergent/3983870 to your computer and use it in GitHub Desktop.
Using mechanize with proxy and basic auth
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
agent.set_proxy('proxy.example.com', 80, 'username', 'password')
agent.add_auth('http://hoge.com','b_username','b_password')
agent.user_agent_alias = "Windows Mozilla"
res = agent.get('http://hoge.com/some/page')
puts res.body
@maynardo
Copy link

how would you test the connection to the proxy before setting it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment