#!/usr/bin/perl # What's Wrong with LWP::Simple::get ? use strict; use LWP::UserAgent; use LWP::Simple; use constant URL => 'http://www.google.com'; main(); exit(0); sub main { print "Content-type: text/html\n\n"; print "Fetching '" . URL . "' with LWP::UserAgent\n
\n"; my $ua = LWP::UserAgent->new(); my $response = $ua->get(URL); if ( $response->is_success ) { my $len = length($response->content); print "Retrieved $len bytes\n
\n"; } else { my $code = $response->code; print "Failed to retrieve URL: $code\n
\n"; } print "Fetching '" . URL . "' with LWP::Simple\n
\n"; my $content = LWP::Simple::get( URL ); if ( $content ) { my $len = length($content); print "Retrieved $len bytes\n
\n"; } else { print "Failed to retrieve URL\n
\n"; } } #### Content-type: text/html Fetching 'http://www.google.com' with LWP::UserAgent
Retrieved 9972 bytes
Fetching 'http://www.google.com' with LWP::Simple
Retrieved 10044 bytes
##
## Fetching 'http://www.google.com' with LWP::UserAgent
Failed to retrieve URL: 500
Fetching 'http://www.google.com' with LWP::Simple
Failed to retrieve URL
##
## Fetching 'http://www.google.com' with LWP::UserAgent
Retrieved 10026 bytes
Fetching 'http://www.google.com' with LWP::Simple
Retrieved 10008 bytes