Hammy has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am trying to use LWP to print out an image. When I put the URL in the browser, it properly returns the image. When I use LWP, it returns a different representation of the image and all I see if special characters. Here is the URL that I call that returns a map if you put it in the browser.
http://xml.sa.mapquest.com:80/?transaction=mapimage&datalen=153&data=7 +1e3Q01g%7EgHl04e%28cN1os1%22%3E0wR3KkDxayw%7CY%25+0As9wU75kgit%24TU%3 +Dna%3FH%3EJh9FL7nFsU40%5DltBFj%3A%2Bv%26b%7B2Ys2xuSx%23kMobGl%2B+tvDh +BP%23%2CbF8b29
Here is the code I use to try to get Perl to print out the same image. I stole this code from a seperate thread here on perlmonks.com. I wrote my own code and got the same result.
my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; $mapURL = "http://xml.sa.mapquest.com:80/?transaction=mapimage&datalen +=153&data=71e3Q01g%7EgHl04e%28cN1os1%22%3E0wR3KkDxayw%7CY%25+0As9wU75 +kgit%24TU%3Dna%3FH%3EJh9FL7nFsU40%5DltBFj%3A%2Bv%26b%7B2Ys2xuSx%23kMo +bGl%2B+tvDhBP%23%2CbF8b29" my $response = $ua->get($mapURL, 'User-Agent' => 'Mozilla/5.0 [en] (Windows; U; Windows NT 6.0)', 'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, i +mage/png, */*', 'Accept-Charset' => 'iso-8859-1,*,utf-8', 'Accept-Language' => 'en-US', ); if ($response->is_success) { print $response->content; }
Thanks in advance for whatever suggestions you may have for me.

Replies are listed 'Best First'.
Re: Error Using LWP to display an image
by Anonymous Monk on Jun 26, 2008 at 03:17 UTC
    Oh Hammy, an image is data. A browser (like firefox) knows how to interpret that data to draw you a picture on the screen. LWP doesn't do that (its not that kind of browser), and neither does your shell .