Ok, interesting. I tried that myself and I couldn't get it to work either. I then tried subclassing LWP::UserAgent, and overriding the get_basic_credentials method (you should have a program called lwp_request, the source of which should provide an example). I tested my bot with my local cups server, which requires HTTP authentication, and it worked.

code shown below:

#!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; { #Create a new package that subclasses LWP::UserAgent. # we do this to allow overriding of the get_basic_credentials( +) method. package RequestAgent; our @ISA = qw(LWP::UserAgent); # All other subs would come from LWP::UserAgent. sub get_basic_credentials { #we only return the password for one location, so no m +agic necessary return ("user", "password"); } } my $ua = RequestAgent->new(); my $response = $ua->get("http://host:port/location"); die "Error while getting ", $response->request->uri, " -- ", $response->status_line, "\nAborting" unless $response->is_success; print $response->content, "\n";
(You'll have to comment out the "use warnings" line again)
I'm not sure why the first version didn't work - perhaps I didn't understand the docs correctly

Update: LTjake got there first.


davis
It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.

In reply to Re: Re: Re: Basic authentication with LWP::UserAgent by davis
in thread Basic authentication with LWP::UserAgent by abeal

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.