title: Mechanize and NTLM Authentication
body: <p>The following code generates a 401 => Net::HTTPUnauthorized error.  </p>
  
  <p>From the log:</p>
  
  <pre><code>
  response-header: x-powered-by => ASP.NET
  response-header: content-type => text/html  
  response-header: www-authenticate => Negotiate, NTLM  
  response-header: date => Mon, 02 Aug 2010 19:48:17 GMT  
  response-header: server => Microsoft-IIS/6.0  
  response-header: content-length => 1539  
  status: 401
  </code></pre>
  
  <p>The Script is as follows:  </p>
  
  <pre><code>
  require 'rubygems'  
  require 'mechanize'  
  require 'logger'  
  
  agent = WWW::Mechanize.new { |a| a.log = Logger.new("mech.log") }  
  
  agent.user_agent_alias = 'Windows IE 7'  
  
  agent.basic_auth("username","password")   
  
  page = agent.get("http://server/loginPage.asp")
  </code></pre>
  
  <p>I believe the reason for the 401 is that I need to be authenticating using NTLM, but I have been unable to find a good example of how to do this.</p>