机械化和NTLM身份验证 [英] Mechanize and NTLM Authentication

查看:86
本文介绍了机械化和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'

这篇关于机械化和NTLM身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆