ntlm.html
来自「perl教程」· HTML 代码 · 共 137 行
HTML
137 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../../displayToc.js"></script>
<script language="JavaScript" src="../../../tocParas.js"></script>
<script language="JavaScript" src="../../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../../scineplex.css">
<title>LWP::Authen::Ntlm - Library for enabling NTLM authentication in LWP</title>
<link rel="stylesheet" href="../../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',3);</script>
<h1><a>LWP::Authen::Ntlm - Library for enabling NTLM authentication in LWP</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#usage">USAGE</a></li>
<li><a href="#availability">AVAILABILITY</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>LWP::Authen::Ntlm - Library for enabling NTLM authentication (Microsoft) in LWP</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">use</span> <span class="variable">LWP::UserAgent</span><span class="operator">;</span>
<span class="keyword">use</span> <span class="variable">HTTP::Request::Common</span><span class="operator">;</span>
<span class="keyword">my</span> <span class="variable">$url</span> <span class="operator">=</span> <span class="string">'http://www.company.com/protected_page.html'</span><span class="operator">;</span>
</pre>
<pre>
<span class="comment"># Set up the ntlm client and then the base64 encoded ntlm handshake message</span>
<span class="keyword">my</span> <span class="variable">$ua</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">LWP::UserAgent</span><span class="operator">(</span><span class="string">keep_alive</span><span class="operator">=></span><span class="number">1</span><span class="operator">);</span>
<span class="variable">$ua</span><span class="operator">-></span><span class="variable">credentials</span><span class="operator">(</span><span class="string">'www.company.com:80'</span><span class="operator">,</span> <span class="string">''</span><span class="operator">,</span> <span class="string">"MyDomain\\MyUserCode"</span><span class="operator">,</span> <span class="string">'MyPassword'</span><span class="operator">);</span>
</pre>
<pre>
<span class="variable">$request</span> <span class="operator">=</span> <span class="variable">GET</span> <span class="variable">$url</span><span class="operator">;</span>
<span class="keyword">print</span> <span class="string">"--Performing request now...-----------\n"</span><span class="operator">;</span>
<span class="variable">$response</span> <span class="operator">=</span> <span class="variable">$ua</span><span class="operator">-></span><span class="variable">request</span><span class="operator">(</span><span class="variable">$request</span><span class="operator">);</span>
<span class="keyword">print</span> <span class="string">"--Done with request-------------------\n"</span><span class="operator">;</span>
</pre>
<pre>
<span class="keyword">if</span> <span class="operator">(</span><span class="variable">$response</span><span class="operator">-></span><span class="variable">is_success</span><span class="operator">)</span> <span class="operator">{</span><span class="keyword">print</span> <span class="string">"It worked!->"</span> <span class="operator">.</span> <span class="variable">$response</span><span class="operator">-></span><span class="variable">code</span> <span class="operator">.</span> <span class="string">"\n"</span><span class="operator">}</span>
<span class="keyword">else</span> <span class="operator">{</span><span class="keyword">print</span> <span class="string">"It didn't work!->"</span> <span class="operator">.</span> <span class="variable">$response</span><span class="operator">-></span><span class="variable">code</span> <span class="operator">.</span> <span class="string">"\n"</span><span class="operator">}</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p><code>LWP::Authen::Ntlm</code> allows LWP to authenticate against servers that are using the
NTLM authentication scheme popularized by Microsoft. This type of authentication is
common on intranets of Microsoft-centric organizations.</p>
<p>The module takes advantage of the Authen::NTLM module by Mark Bush. Since there
is also another Authen::NTLM module available from CPAN by Yee Man Chan with an
entirely different interface, it is necessary to ensure that you have the correct
NTLM module.</p>
<p>In addition, there have been problems with incompatibilities between different
versions of Mime::Base64, which Bush's Authen::NTLM makes use of. Therefore, it is
necessary to ensure that your Mime::Base64 module supports exporting of the
encode_base64 and decode_base64 functions.</p>
<p>
</p>
<hr />
<h1><a name="usage">USAGE</a></h1>
<p>The module is used indirectly through LWP, rather than including it directly in your
code. The LWP system will invoke the NTLM authentication when it encounters the
authentication scheme while attempting to retrieve a URL from a server. In order
for the NTLM authentication to work, you must have a few things set up in your
code prior to attempting to retrieve the URL:</p>
<ul>
<li>
<p>Enable persistent HTTP connections</p>
<p>To do this, pass the "keep_alive=>1" option to the LWP::UserAgent when creating it, like this:</p>
<pre>
<span class="keyword">my</span> <span class="variable">$ua</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">LWP::UserAgent</span><span class="operator">(</span><span class="string">keep_alive</span><span class="operator">=></span><span class="number">1</span><span class="operator">);</span>
</pre>
</li>
<li>
<p>Set the credentials on the UserAgent object</p>
<p>The credentials must be set like this:</p>
<pre>
<span class="variable">$ua</span><span class="operator">-></span><span class="variable">credentials</span><span class="operator">(</span><span class="string">'www.company.com:80'</span><span class="operator">,</span> <span class="string">''</span><span class="operator">,</span> <span class="string">"MyDomain\\MyUserCode"</span><span class="operator">,</span> <span class="string">'MyPassword'</span><span class="operator">);</span>
</pre>
<p>Note that you cannot use the HTTP::Request object's <code>authorization_basic()</code> method to set
the credentials. Note, too, that the 'www.company.com:80' portion only sets credentials
on the specified port AND it is case-sensitive (this is due to the way LWP is coded, and
has nothing to do with LWP::Authen::Ntlm)</p>
</li>
</ul>
<p>If you run into trouble and need help troubleshooting your problems, try enabling LWP
debugging by putting this line at the top of your code:</p>
<pre>
<span class="keyword">use</span> <span class="variable">LWP::Debug</span> <span class="string">qw(+)</span><span class="operator">;</span>
</pre>
<p>You should get copious debugging output, including messages from LWP::Authen::Ntlm itself.</p>
<p>
</p>
<hr />
<h1><a name="availability">AVAILABILITY</a></h1>
<p>General queries regarding LWP should be made to the LWP Mailing List.</p>
<p>Questions specific to LWP::Authen::Ntlm can be forwarded to <a href="mailto:jtillman@bigfoot.com">jtillman@bigfoot.com</a></p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright (c) 2002 James Tillman. All rights reserved. This
program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../../lib/LWP.html">the LWP manpage</a>, <a href="../../../lib/LWP/UserAgent.html">the LWP::UserAgent manpage</a>, <a href="../../../lib/lwpcook.html">the lwpcook manpage</a>.</p>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?