 <p>A web proxy is not normally defined by <em>just</em> a port, but is usually a full host name. Charles is very likely installed on localhost. Therefore the following adjustment may work for you:</p> <pre><code>@agent ||= Mechanize.new do |agent| agent.set_proxy("localhost", 8888) end </code></pre>