I'm trying to get LWP to work against an IIS server configured with NTLM authentication. When NTLM authentication is turned off on the server, the code work fine, so I assume that the only problem here is the NTLM authentication.
So far, I have the following:
my $ua = LWP::UserAgent->new(agent => "whatever",
timeout => $timeout, keep_alive => 1);
$ua->credentials('hostname:80', '', $username, $password);
my $hdr = HTTP::Headers->new("Content-Type" => "text/xml; charset=UTF-8",
"SOAPAction" => "\"whatever\"");
my $req = HTTP::Request->new("POST" => $url, $hdr, encode_utf8($post));
$res = $ua->request($req);
If I turn on debugging, I get the following messages:
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: POST http://hostname
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::http::request: Keep the http connection to hostname:80
LWP::UserAgent::request: Simple response: Unauthorized
LWP::Authen::Ntlm::authenticate: authenticate() has been called
Use of uninitialized value in exists at /usr/lib/perl5/vendor_perl/5.8.5/LWP/UserAgent.pm line 560.
Use of uninitialized value in hash element at /usr/lib/perl5/vendor_perl/5.8.5/LWP/UserAgent.pm line 561.
LWP::Authen::Ntlm::authenticate: In first phase of NTLM authentication
[Thu Apr 12 13:55:28 2012] [error] Wide character in subroutine entry at /usr/lib/perl5/site_perl/5.8.5/Authen/NTLM.pm line 346.\n
LWP::Protocol::collect: read 625 bytes
LWP::UserAgent::request: Simple response: Internal Server Error
Trying to access the same URL with wget
works fine. The documentation for MIME::Base64
says that the encode function will croak with Wide character in subroutine entry
if $bytes contains characters with code above 255.
Am I missing something essential here, or could this be a bug in Authen::NTLM
?
LWP::Authen::Ntlm
says 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. Maybe this is the problem? – Borodin$username
or$password
contain non-ascii characters by any chance? – Cosimodomain\username
). That got me fewer messages about uninitialized values, but same error message in the end. – Vetle