Hello, I am trying to write a small script that logs in to a webpage that is protected with a Basic / Digest authentication. I am however unable to log in via WWW::Mechanize and LWP::UserAgent. I've tried these code examples, without avail.

1:

my $username = "someuser"; my $password = "password"; my $url = 'http://sub.example.com:49282/navigation/nav_home.shtml'; use LWP::UserAgent; $ua = LWP::UserAgent->new; $req = HTTP::Request->new(GET => $url); $req->authorization_basic($username,$password); print $ua->request($req)->as_string;

2:

## LWP! use LWP; use strict; my $username = 'username'; my $password = 'password'; my $url = 'http://server:49282/subpage/nav_home.shtml'; my $browser = LWP::UserAgent->new('Mozilla'); $browser->credentials("server:49282","Digest realm",$username=>$passwo +rd); my $response=$browser->get($url); print $response->content();

3:

## WWW::Mechanize #!/usr/bin/perl use WWW::Mechanize; my $username = 'username'; my $password = 'password'; my $url = 'http://server:49282/subpage/nav_home.shtml'; # Create a new instance of WWW::Mechanize my $mechanize = WWW::Mechanize->new(autocheck => 1); # Supply the necessary credentials $mechanize->credentials("server:49282","Digest realm", $username=>$pas +sword); $mechanize->get($url); # Retrieve the desired page print $mechanize->content();

The site I try to log in to should not have any fancy mechanics to avoid being logged into via Scripts. ANy ideas or examples of how I can log in? From what I've read up on Basic authentication, it can't authenticate until it has got the WWW-Authorization header from the server, which is what I've loaded up the correct credentials for. I've also tried to load the page, do the "reply" in terms of credentials, without success.

In reply to Basic / Digest authentication in website by TheFlyingCorpse

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.