Jeff Davis wrote:
: I'm using LWP to fetch an image and attempting to save it locally.
: The file is successfully created, however all it contains is:
:
: HTTP::Response=HASH(0x8380464)
:
: Here's the code snippet:
:
: $file = "/home/images/$name";
: open(IMAGE, ">$file") || die "unable to open filehandle $file \n";
: $saveres = $ua->request(HTTP::Request->new(GET => $pic));
: print IMAGE "$saveres";
$ua->request returns an HTTP::Response object. You can get to its
content through the content() method:
$saveres = $ua->request(HTTP::Request->new(GET => $pic))->content();
or more readably,
$response = $ua->request(HTTP::Request->new(GET => $pic));
$saveres = $response->content();
That makes it easy to check whether the request succeeded:
if ( $response->is_success() ) {
$saveres = $response->content();
} else {
# handle the error...
}
Do "perldoc HTTP::Response" for more info.
-- tdk