LWP Code

Hi All,

Here is a first pass at coding for using LWP directly...

--------------------------
Old code:
--------------------------
open( URI, "$grabber \"$uri_escaped\" |" ) || die "couldn't retrieve
uri: $!";
@file = <URI>;
close( URI ) || die "couldn't close uri retrieval pipe: $!";

# skip the request headers
while ( $_ = shift( @file ) ) {
    chop;
    last if /^$/;
}

# check the response headers
while ( $_ = shift( @file ) ) {
    chop;
    if (/^HTTP\/[0-9\.]+ [0-9][0-9][0-9] .*/ ) {
        ( ( $httpversion, $response, $message ) =
            ( /^(HTTP\/[0-9\.]+) ([0-9][0-9][0-9]) (.*)/ ) );
    }
    if (/^Location: / ) {
        ( ( $redirect_uri ) = ( /^Location: (.*)/ ) );
        $redirect_uri =~ s/\s*$//g;     # it has a trailing space
sometimes (?)
    }
    last if /^$/;
}
--------------------------
New Code:
--------------------------
require LWP::UserAgent;

$ua=new LWP::UserAgent;
$request=new HTTP::Request('GET',$uri_escaped);

$my_response=$ua->request($request);
($response,$message)=($my_response->status_line=~/([0-9][0-9][0-9])
(.*)/);
@file=split(/^/,$my_response->content);
--------------------------
Hope this helps. Also, is a gz of the sgml-lib directory available ?

Randy Winch

Received on Wednesday, 26 August 1998 04:39:29 UTC