Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

quick LWP question

by vxp (Pilgrim)
on Jun 23, 2009 at 15:49 UTC ( #774067=perlquestion: print w/ replies, xml ) Need Help??
vxp has asked for the wisdom of the Perl Monks concerning the following question:

this has got to be something simple/stupid :)

I'm trying to authenticate to a website and grab a file and I'm failing to see what I'm doing wrong here:

#!/usr/bin/perl use strict; use LWP; my $browser = LWP::UserAgent->new( ); $browser->credentials(" +w.pcgi?DEVICE=WLC&JOB_TYPE=download&TITLE=1&JOB_STATUS=any", "EMAN Pr +otected Resource", "myusername", "mypassword"); my $response = $browser->get(" +/View.pcgi?DEVICE=WLC&JOB_TYPE=download&TITLE=1&JOB_STATUS=any"); print $response->content;

The thing of it is, I *KNOW* that my realm/username/pass is correct (I can auth just fine with wget, or a regular browser for instance).. but for some reason, the above code fails to authenticate. any idea what I'm doing wrong here?

Comment on quick LWP question
Download Code
Replies are listed 'Best First'.
Re: quick LWP question
by Mutant (Priest) on Jun 23, 2009 at 15:58 UTC
    From the LWP::UserAgent POD:
    The $netloc is a string of the form "<host>:<port>". The username and password will only be passed to this server
    $netloc being the first param to credentials. So you need to remove the path and the preceding "http://" from the first param, and just use "".
Re: quick LWP question
by davorg (Chancellor) on Jun 23, 2009 at 16:01 UTC

    From the LWP::UserAgent documentation:

    $ua->credentials( $netloc, $realm, $uname, $pass )

    Get/set the user name and password to be used for a realm.

    The $netloc is a string of the form "<host>:<port>". The username and password will only be passed to this server. Example:

    $ua->credentials("", "Some Realm", "foo", "secret");

    Doesn't look like the value you're using for $netloc follows the format defined in the docs.


    See the Copyright notice on my home node.

    Perl training courses

      I tried both ways, including:
      $browser->credentials("", "EMAN Protected Resour +ce", "myusername", "mypassword");

      .. with the same (failed) result

        Please provide the response (print $response->as_string;)
Re: quick LWP question
by imrags (Monk) on Jun 24, 2009 at 10:41 UTC
    Can you please try this:
    use LWP::UserAgent; my $LWPUA=new LWP::UserAgent(); $LWPUA->credentials((" +w.pcgi?DEVICE=WLC&JOB_TYPE=download&TITLE=1&JOB_STATUS=any", "EMAN Pr +otected Resource", "myusername", "mypassword"); print $LWPUA->get(" +/View.pcgi?DEVICE=WLC&JOB_TYPE=download&TITLE=1&JOB_STATUS=any")->con +tent;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://774067]
Approved by Mutant
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2016-05-26 02:18 GMT
Find Nodes?
    Voting Booth?