LWP::UserAgent and HTTP::Request with basic authentication...

S

scottny07

I am by no means a perl pro but I am trying to take a url sent from a
form along with a integer and load the given number of URL's to
recache them in our cms system... here is what I have...

#!/usr/local/bin/perl
alarm(300);

use LWP::UserAgent;
use HTTP::Request;
use CGI qw/:all/;
my $query = new CGI;

my $URL = CleanUp($query->param('gURL'));
my $imgCount = CleanUp($query->param('imgCount'));

## Ok, now we can actually begin the refreshing
#
my $orig = $URL;
for(my $i=1; $i <= $imgCount; $i++) {
$URL =~ s/Itemnr=\d*//;
$URL =~ s/&nocache=1//;
$URL = $URL . "&Itemr=$i&nocache=1";
print "Re-Caching image($i) ";

## Here is where we want to authenticate the access to the edit
server
my $ua = LWP::UserAgent->new;
$ua->agent("MyAgent/1.0");
my $req = HTTP::Request->new(GET => $URL);
$req->authorization_basic('user', 'pass');
my $res = $ua->request($req);
my $content = $res;
if ($content) {
print "<a href='$URL' target='_new'><span class='good'>re-cached</
span></a><br />\n";
} else {
print "<a href='$URL' target='_new'><span class='error'><b>re-cach
failed</b></span></a><br />\n";
}
$URL = $orig;
}
exit(0);

Not working... any ideas?
 
P

Peter Scott

I am by no means a perl pro but I am trying to take a url sent from a
form along with a integer and load the given number of URL's to
recache them in our cms system... here is what I have... [snip]
$ua->agent("MyAgent/1.0");
my $req = HTTP::Request->new(GET => $URL);
$req->authorization_basic('user', 'pass');
my $res = $ua->request($req);
my $content = $res;
if ($content) { [snip]
Not working... any ideas?

You will need to be less of a Perl pro if you use the simpler
WWW::Mechanize. And if you supply more detail than "not working".

Shot in the dark: you probably want to be checking for an HTTP error
rather than empty content.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top