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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.