in reply to LWP + NTLM over HTTPS?

I had a script similar to yours:
#!/usr/local/bin/perl use strict; use warnings; use LWP::UserAgent::Determined; use HTTP::Request::Common; use Authen::NTLM; ntlmv2(1); my $url = 'http://www.bbc.co.uk/'; my $ua = LWP::UserAgent::Determined->new(keep_alive=>1); $ua->credentials('www.bbc.co.uk:80', '', 'mydomain\\myuser', 'mypass') +; my $request = GET $url; print "--Performing request now...-----------\n"; my $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"} my $contents = $response->content(); print $response->status_line(), "\n"; print $response->headers()->as_string(), "\n";

Replies are listed 'Best First'.
Re^2: LWP + NTLM over HTTPS?
by jphekman (Novice) on Apr 17, 2010 at 19:44 UTC
    When I run this script I get
    Undefined subroutine &main::ntlmv2 called at ./connectTest5.pl line 8.
    I commented out the ntlmv2 call, just to see what would happen. Now it compiles and sends the request to the server. This client actually prints headers for me, so that's really helpful! One of the headers says:
    Client-SSL-Warning: Peer certificate not verified Client-Warning: Authen::NTLM version 1.02 required--this is only versi +on 0.31 at /usr/share/perl/5.10/Exporter/Heavy.pm line 108. BEGIN failed--compilation aborted at /usr/local/share/perl/5.10.0/LWP +/Authen/Ntlm.pm line 8. Compilation failed in require at (eval 23) line 3. MicrosoftOfficeWebServer: 5.0_Pub

    I am confused. a) Authen::NTLM 0.31 is the most recent version on CPAN. Perhaps this client is expecting the other NTLM module? b) Ntlm.pm failed to compile, apparently! Previous scripts using it did seem to compile, though.

    So, seeing the headers is helpful, but I'm still not there yet. Thanks!

      Since you're using Microsoft, take out Authen::NTLM. I use that for my Linux systems sometimes but not always. With Microsoft, LWP uses LWP::Authen::Ntlm indirectly, so you wouldn't normally need to use Authen::NTLM in your script.

        Ah! I got it working. I would not have been able to do so if you had not pointed out how to display the headers, which were invaluable in debugging. Thank you.

        For posterity (since most of the useful information I found about LWP and NTLM I found on PerlMonks): the problem was that I had the wrong NTLM module installed. There appear to be three modules on CPAN called NTLM. I'd found some post saying there were two.

        1. There is Authen::NTLM which only goes up to version 0.31 or so. This is not what you want, and when you install it, it will get run, and will not compile properly -- well, that was what happened to me. I uninstalled this entirely.

        2. There is the NTLM inside of LWP. Which seems at first to be what you want. But when I ran with Authen::NTLM uninstalled, I got the error "Unsupported authentication scheme 'ntlm'". Which suggests that NTLM is not properly installed. Confusing, since I saw an Ntlm.pm on my hard drive in what looked like the appropriate place! I eventually discovered --

        3. http://search.cpan.org/dist/NTLM/. Different from #1, as its version number is 1.05. Also, I believe it somehow installs inside of LWP, or makes itself available to LWP, or something. (I clearly don't know much about how this all works; monks should feel free to correct me.) Once I had installed that, things started working.

        Because the server I'm using is using HTTPS, I also had to futz some with certificates and passphrases, but that is incidental to the above problem, which was the big one.

        Thanks again for the help.

        Jessica

        (FWIW, I am not using Microsoft, although the remote server I'm trying to access must be, so far as I know.)

        When I remove Authen::NTLM from the script which you gave me above, I do end up with the same errors as when it was in: undefined subroutine ntlmv2, or if I comment out that line, then the failure to compile of /usr/local/share/perl/5.10.0/LWP/Authen/Ntlm.pm

        Thanks for your help so far!

        Jessica