以下代碼會生成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來驗證,但我一直無法找到一個如何做到這一點的好例子。
這使我更接近 http://speakmy.name/2010/01/19/ntlm-authentication-for-ruby-with-typhoeus-and-curl/ 我設置了ntlmaps代理,但可以沒有看到得到那個工作 – 2010-08-03 15:55:44