2010-08-02 87 views
1

以下代碼會生成401 => Net :: HTTPUnauthorized錯誤。機械化和NTLM身份驗證

從日誌:


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來驗證,但我一直無法找到一個如何做到這一點的好例子。

+0

這使我更接近 http://speakmy.name/2010/01/19/ntlm-authentication-for-ruby-with-typhoeus-and-curl/ 我設置了ntlmaps代理,但可以沒有看到得到那個工作 – 2010-08-03 15:55:44

回答

-1

機械化2支持NTLM AUTH:

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

沒有方法用戶名= For Mechanize :: Agent – iGallina 2014-04-02 19:34:34