This is my first posting to the Perl Monks so if I'm missing any information please be sure to let me know.
I'm trying to perl-script a POST to a NTLM-protected web site. Both boxes are Windows. Mine is XP - not sure what the server is.
I can use my IE browser with no problems at all. If I specify just the url it doesn't even ask me for my username/password. If I specify the complete url (domain and all) it pops up a text message box asking for my username/password. Typing them in also works the way its expected.
I'm running ActiveState perl v5.8.8 and no matter what code I try - and I've been all over the internet trying MANY examples - I can't get pass the level 2 NTLM challange. I see level 1 in the debug output then level 2 and then it goes right back to level 1 and 401's-me.
I've included the code (and the response) for what I thought should work but this version doesn't even get me to level 1. I've tried everything that's "standard" and recommended with no success whatsoever.
For our security purposes, actual urls, domain names,username, and password are represented by generic strings enclosed with arrows.
#!/usr/bin/perl -w # test_NTLM-9.pl use strict; use LWP::UserAgent; use LWP::Debug qw(+); my $page = ""; my $response = ""; my $ua = ""; my %reports = (); my $url1 = "http://<some url>/reports.asp"; my $url2 = "http://<some url>.<some domain>.com:80/reports.asp"; { package RequestAgent; our @ISA = qw(LWP::UserAgent); sub get_basic_credentials { return ("<DOMAIN\\username>", "<passowrd>"); } } $ua = RequestAgent -> new (keep_alive => 1); $response = $ua -> post ($url2, \%reports, ['report' => 'E911 Numbers' +]); if ($response -> is_success) { print ("\nGOOD\n"); $page = $response -> code; } else { print ("\nBAD\n"); $page = $response -> code; } if (defined ($page)) { $page =~ s/<br>/\\\n/g; print ($page); } exit;
C:\> test_NTLM-9.pl LWP::UserAgent::new: () LWP::UserAgent::request: () LWP::UserAgent::send_request: POST http://<some url>.<some domain>.com +:80/reports. asp LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 811 bytes LWP::Protocol::collect: read 3620 bytes LWP::UserAgent::request: Simple response: Unauthorized BAD 401 C:\>
ANY help is greatly appreciated. Thank you in advance.
20070320 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
In reply to LWP::UserAgent Authentication by palladinob
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |