LWP credentials help

N

Nalli

use LWP:
$url = 'https://www.something.com/somethingelse/whatever' ;

$ua = LWP::UserAgent->new;
$ua->timeout(45);
$ua->env_proxy;
$ua->agent("Mozilla/5.01 (Windows; U; NT4.0; en-us) Gecko/
25250101");
$ua->credentials( $url, $url, "username", "password" );
$response = $ua->get($url);

if ($response->is_success)
{
print $html;
}

In order to access $url a username and password are required. The
problem is that I dont know hwo to pass the credentials in order to
successfully access the page. Can someone please tell me how to pass
my login information?

Thank you in advance.
 
J

Jamie

In said:
use LWP:
$url = 'https://www.something.com/somethingelse/whatever' ;

$ua = LWP::UserAgent->new;
$ua->timeout(45);
$ua->env_proxy;
$ua->agent("Mozilla/5.01 (Windows; U; NT4.0; en-us) Gecko/
25250101");
$ua->credentials( $url, $url, "username", "password" );
$response = $ua->get($url);

if ($response->is_success)
{
print $html;
}

In order to access $url a username and password are required. The
problem is that I dont know hwo to pass the credentials in order to
successfully access the page. Can someone please tell me how to pass
my login information?

The way I've done this in the past was to override LWP::UserAgent
and supply my own get_basic_credentials method. Then, from there
you can either just return them, prompt the user for them, look them
up in a database, etc.. Seems a little involved at first, but it's
not that bad.

Jamie
 
P

Peter Scott

In <[email protected]>,
"Nalli" <[email protected]> mentions: [...]
$ua->agent("Mozilla/5.01 (Windows; U; NT4.0; en-us) Gecko/
25250101");
$ua->credentials( $url, $url, "username", "password" ); [...]
In order to access $url a username and password are required. The
problem is that I dont know hwo to pass the credentials in order to
successfully access the page. Can someone please tell me how to pass my
login information?

The way I've done this in the past was to override LWP::UserAgent and
supply my own get_basic_credentials method. Then, from there you can
either just return them, prompt the user for them, look them up in a
database, etc.. Seems a little involved at first, but it's not that bad.

And it's precisely because it's involved that I supplied a patch that was
incorporated into the latest WWW::Mechanize to simplify it. Use that
module instead and all you need to do is:

$mech->credentials( $username, $password );

It should be as easy for the programmer as it is for the browser user,
otherwise you're doing work that the computer could do for you.
 

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,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top