Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

NTLM authentication fails with WWW:Mechanize, fine with LWP::UserAgent

by reasonablekeith (Deacon)
on May 22, 2009 at 10:09 UTC ( [id://765651]=perlquestion: print w/replies, xml ) Need Help??

reasonablekeith has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

A little help please. I need to write some test scripts over our company sharepoint intranet (from and to windows), so to that end I need to authenicate through NTLM. No problem, I've updated libperl-www to 5.862, and set up the following...

use LWP::UserAgent; my $ua = new LWP::UserAgent('keep_alive' => '1'); my $url = 'http://intranet/mypage'; $ua->credentials('intranet:80', '', "domain\\user", 'pass'); my $response =$ua->get($url); print $response->code();
The above works just fine and returns a response code of 200, groovey. However, as I'll be following links, submitting forms etc, I'd obviously much rather use Mechanize. As I beleive Mechanize is built over LWP, I don't think this should be a problem, so try the following...
use WWW::Mechanize; my $mech = WWW::Mechanize->new('keep_alive' => 1); $mech->credentials('intranet:80', '', "domain\\user", 'pass'); $mech->get( 'http://intranet/mypage' ); print $mech->status();
Unfortunately, I can't get anything other than a 401 unauthorized out of this. I'm not sure how to attack this, so any advice much appreciated.

Thanks,

Rob

---
my name's not Keith, and I'm not reasonable.

Replies are listed 'Best First'.
Re: NTLM authentication fails with WWW:Mechanize, fine with LWP::UserAgent
by Anonymous Monk on May 22, 2009 at 11:51 UTC
    Try upgrading both LWP and WWW::Mechanize, and try turning on debugging
      Both are up-to-date via activestate's ppms.

      I'm not sure how to turn on debugging though, I've tried

      use LWP::Debug qw(+);
      but it doesn't seem to make any difference.
      ---
      my name's not Keith, and I'm not reasonable.
        Both are up-to-date via activestate's ppms.

        Then they are not up-to-date (at least WWW::Mechanize isn't up to date, the version on activestate's repository is ancient).

        I'm not sure how to turn on debugging though, I've tried

        perldoc LWP::Debug

        use LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->default_header('Accept-Encoding' => scalar HTTP::Message::decodab +le()); $ua->add_handler("request_send", sub { shift->dump; return }); $ua->add_handler("response_done", sub { shift->dump; return }); $ua->get("http://www.example.com");
Re: NTLM authentication fails with WWW:Mechanize, fine with LWP::UserAgent
by reasonablekeith (Deacon) on Jun 02, 2009 at 11:52 UTC
    I'm still banging my head on this one. I've tried using LWP to generate a valid authentication string, and passing that in the headers of a mech request, but that's not working either, presumably because I'm being issued another challenge.

    Any pointers would be much appreciated.

    ---
    my name's not Keith, and I'm not reasonable.

      You will need a version of WWW::Mechanize of at least 1.52 or greater, as the changes in the credentials API of LWP::UserAgent did not get mirrored by similar changes in WWW::Mechanize until then.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://765651]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found