#!/usr/bin/perl -w
use strict;
# use LWP class, no importing to this namespace
require LWP::UserAgent;
# make a generic subroutine that retrieves a URI for you
sub getURI {
# obtain the uri that has been requested. if we got bad
# input or no input, I'm leaving the error handling to LWP
# and HTTP::Request -which is just fine.
my($uri) = shift(@_);
# create an instance (an "object") of the LWP::UserAgent class
my($lwp) = LWP::UserAgent->new();
# set the type of user agent which you are going to masquerade
$lwp->agent('Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)');
# create HTTP::Request object from prepared uri
my($request) = HTTP::Request->new('GET', $uri);
# useful if you want to see the http request which
# you are about to make with LWP. uncomment this
# if that is the case, then comment it out again
# to resume normal execution
# V V
# | |
# | |
# v v
#print($request->as_string()) and exit;
# make the request, store what gets returned
my($response) = $lwp->request($request);
# hand it over to the requesting entity
return($response->as_string());
}
# use the subroutine you just made to get the web address you need
my($want) = 'http://ooopps.sourceforge.net/cgi-bin/ismeonline.pl';
# print out the returned content
print( &getURI($want) );