Perl: LWP Example
LWP Example
$ua = new LWP::UserAgent;
# Create user agent - this is what retrieves pages
# The string passed here is what shows up in the UA field in the server logs
$ua->agent("A cool Perl Client");
# If you need a proxy, enter that info here...
# $ua->proxy(['http', 'ftp'], 'http://webcache.east:8080/');
# The UA is all set, lets create a Request object:
$req = new HTTP::Request;
$req->url("http://www.merrimack.edu"); # The URL we want
$req->method("GET"); # How to retrieve the URL
$response = $ua->request($req); # Send the request, get the response
my $txt = $response->as_string(); # call the as_string() method of the response
print "txt = $txt\n"; # print it out
This example retrieves the merrimack.edu home page, and prints out the HTML text