机械化和NTLM身份验证

机械化和NTLM身份验证

问题描述:

以下代码生成401 => Net :: HTTPUnauthorized错误.

The following code generates a 401 => Net::HTTPUnauthorized error.

从日志中:


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

脚本如下:


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")

我相信401的原因是我需要使用NTLM进行身份验证,但是我一直找不到如何做到这一点的好例子.

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.

机械化2支持NTLM身份验证:

Mechanize 2 supports NTLM auth:

m = Mechanize.new
m.agent.username = 'user'
m.agent.password = 'password'
m.agent.domain = 'addomain'