title: "Hostname does not match the server certificate" error in Mechanize and HTTParty
body: <p>Occationally, when I visit a website with <code>HTTParty</code> or <code>Mechanize</code>, I get this error:</p>
  
  <pre><code>hostname "www.example.com" does not match the server certificate
  </code></pre>
  
  <p>I can see that <a href="https://stackoverflow.com/questions/4505795/rails-3-opensslsslsslerror-hostname-was-not-match-with-the-server-certific">there is a workaround</a> if you use the <code>open</code> method, but I'm not sure how to leverage that the above gems.</p>
  
  <p>Stacktrace for <code>Mechanize</code>:</p>
  
  <pre><code>agent = Mechanize.new
  agent.read_timeout              = 180
  agent.open_timeout              = 180
  agent.user_agent_alias          = 'Mac Safari'
  agent.redirect_ok               = :all
  agent.follow_meta_refresh       = :anywhere
  agent.follow_meta_refresh_self  = true
  agent.get("https://some-domain.com")
  /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/openssl/ssl.rb:232:in `post_connection_check'
  /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:925:in `connect'
  /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
  /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:858:in `start'
  /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:700:in `start'
  /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:965:in `reset'
  /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:628:in `connection_for'
  /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request'
  /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mechanize-2.7.4/lib/mechanize/http/agent.rb:267:in `fetch'
  /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mechanize-2.7.4/lib/mechanize.rb:464:in `get'
  </code></pre>
  
  <p>Stacktrace for <code>HTTParty</code>:</p>
  
  <pre><code>HTTParty.get("https://some-domain.com")
  /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/openssl/ssl.rb:232:in `post_connection_check'
  /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:925:in `connect'
  /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
  /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:852:in `start'
  /home/me/.rbenv/versions/2.2.2/lib/ruby/2.2.0/net/http.rb:1375:in `request'
  /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/httparty-0.13.7/lib/httparty/request.rb:117:in `perform'
  /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/httparty-0.13.7/lib/httparty.rb:545:in `perform_request'
  /home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/httparty-0.13.7/lib/httparty.rb:476:in `get'
  </code></pre>