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

Discussion in 'Perl Misc' started by scottny07, Mar 29, 2007.

  1. scottny07

    scottny07 Guest

    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?
     
    scottny07, Mar 29, 2007
    #1
    1. Advertising

  2. scottny07

    Peter Scott Guest

    On Thu, 29 Mar 2007 14:08:45 -0700, scottny07 wrote:
    > 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.

    --
    Peter Scott
    http://www.perlmedic.com/
    http://www.perldebugged.com/
     
    Peter Scott, Mar 30, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vinay Gupta
    Replies:
    2
    Views:
    1,116
    Michael Schlenker
    Jul 27, 2004
  2. Steve in NY

    Net::HTTP, LWP::UserAgent, IO::Socket, etc

    Steve in NY, Jul 24, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    108
    Steve in NY
    Jul 25, 2003
  3. jarkun
    Replies:
    1
    Views:
    119
    Charles DeRykus
    Sep 5, 2003
  4. Thomas Kratz

    LWP::UserAgent and basic authentication

    Thomas Kratz, Apr 13, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    231
    Thomas Kratz
    Apr 14, 2005
  5. Phil Powell
    Replies:
    0
    Views:
    282
    Phil Powell
    Feb 18, 2008
Loading...

Share This Page