In the course of trying to get LWP working with NTLM today, I spent some time "Super Searching" Perl Monks. Unfortunately, I did not find a foolproof solution. Nevertheless, I finally got everything working for me. Because this is the newest node I found dealing with NTLM, I thought I'd post my insights here in the hopes that some future searcher has more luck than I did.
The stumbling blocks for me weren't the code, which in the end worked right off the example in the synopsis. Instead, I got tripped up on...
- ... realizing I had to install the Authen::NTLM module. I checked my installation and saw I already had LWP::Authen::Ntlm, so I figured I was set to go. I don't know how it got there without Authen::NTLM, but LWP merrily ran my code without mentioning it didn't have the right modules to do the authentication.
- ... installing the correct module, namely Authen::NTLM by Mark Bush. A man named Yee Man Chan also has packages in the same namespace, for some reason. I am sure his solution is great, too, but it doesn't work with LWP ;-).
- ... patching the NTLM module. Judging by the last release date (2001-10-29), the module has been orphaned. When it didn't work for me, I figured Bill Gates might have changed the protocol, and I was up to my ears in unpacks trying to find the problem before I found this bug report (posted 2005-01-07, by the way, after the initial post in this thread). It proposes a change to one line of code, which I applied manually.
After that, the example code from the synposis ran flawlessly:
use LWP::UserAgent;
use HTTP::Request::Common;
my $url = 'http://www.company.com/protected_page.html'; # Set up the n
+tlm client and then the base64 encoded ntlm handshake message
my $ua = new LWP::UserAgent(keep_alive=>1);
$ua->credentials('www.company.com:80', '', "MyDomain\\MyUserCode", 'My
+Password');
$request = GET $url;
print "--Performing request now...-----------\n";
$response = $ua->request($request);
print "--Done with request-------------------\n";
if ($response->is_success) {
print "It worked!->" . $response->code . "\n"
}
else {
print "It didn't work!->" . $response->code . "\n"
}
Anyway, I hope this can help someone else along the way.