in reply to Re: Re: Basic authentication with LWP::UserAgent
in thread Basic authentication with LWP::UserAgent
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:
(You'll have to comment out the "use warnings" line again)#!/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";
Update: LTjake got there first.
|
|---|