Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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("http://hostname.domain.com:80/OPDATA/Config/Vie +w.pcgi?DEVICE=WLC&JOB_TYPE=download&TITLE=1&JOB_STATUS=any", "EMAN Pr +otected Resource", "myusername", "mypassword"); my $response = $browser->get("http://hostname.domain.com/OPDATA/Config +/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
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 "hostname.domain.com:80".
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("www.example.com:80", "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("hostname.domain.com:80", "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(("http://hostname.domain.com:80/OPDATA/Config/Vie +w.pcgi?DEVICE=WLC&JOB_TYPE=download&TITLE=1&JOB_STATUS=any", "EMAN Pr +otected Resource", "myusername", "mypassword"); print $LWPUA->get("http://hostname.domain.com/OPDATA/Config +/View.pcgi?DEVICE=WLC&JOB_TYPE=download&TITLE=1&JOB_STATUS=any")->con +tent;
    Raghu

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2015-07-01 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (19 votes), past polls