Re: converting Java code to Perl (using LWP?)
- From: Ben Morrow <ben@xxxxxxxxxxxx>
- Date: Sat, 14 Jun 2008 00:33:32 +0100
Quoth PugetSoundSylvia@xxxxxxxxx:
Thanks for your response, Ben. I've posted what I have so far below
(it doesn't work, returns 'Error: 401 Unauthorized').
Also, here's what my limited documentation says:
In order to be allowed through the firewall, users must send an
authentication HTTP header
along with every request.
The header structure is: Authorization: BASIC xxxxxxxxxxxxxxxx?
where xxxxxxx is a firewall user name and password separated by
?:? and converted into BASE64-
encoded format.
***************************************
***************************************
use MIME::Base64;
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET => 'http://SiteName.org/login.php?
name=AppName&pass=AppPWD&service_type=xxx');
$Encoded = encode_base64('FireWallName:FireWallPWD',''); #Encode
into Base64
$FullAuthorization = 'Basic ' . $Encoded; # not sure if Basic is
upper or lower - documentation is contradictory
It's case-insensitive, so either ought to work.
$req->header('Authorization' => $FullAuthorization);
# send request
$res = $ua->request($req);
# check the outcome
if ($res->is_success) {
print $res->decoded_content;
}
else {
print "Error: " . $res->status_line . "\n";
}
That ought to work, I'd say. It would be easier to simply call
$ua->credentials, passing the appropriate information, and let LWP
handle constructing the header for you; finding out what the correct
'netloc' and 'realm' are will mean printing out the contents of the 401
response.
If this doesn't work, add
use LWP::Debug qw/+conns/;
to the top of your script, and post the output.
Ben
--
Many users now operate their own computers day in and day out on various
applications without ever writing a program. Indeed, many of these users
cannot write new programs for their machines...
-- F.P. Brooks, 'No Silver Bullet', 1987 [ben@xxxxxxxxxxxx]
.
- Follow-Ups:
- Re: converting Java code to Perl (using LWP?)
- From: PugetSoundSylvia
- Re: converting Java code to Perl (using LWP?)
- References:
- converting Java code to Perl (using LWP?)
- From: PugetSoundSylvia
- Re: converting Java code to Perl (using LWP?)
- From: Ben Morrow
- Re: converting Java code to Perl (using LWP?)
- From: PugetSoundSylvia
- converting Java code to Perl (using LWP?)
- Prev by Date: Re: calling external program tiff2pdf
- Next by Date: Re: Learning Perl
- Previous by thread: Re: converting Java code to Perl (using LWP?)
- Next by thread: Re: converting Java code to Perl (using LWP?)
- Index(es):
Relevant Pages
|