in reply to Why is my image obtained by LWP displayed as garbage (i.e. plain/text)?

You're printing the image's data as html content. Ofcourse that won't work.

If you're only interested in images, you can do:

#!/usr/bin/perl -T use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); $url = param('name'); print header; print start_html('My Remote Webpage Request Service'); print qq(<img src="$url">); print end_html;

If you want different content types, you should take care of the url's content-type header and respond accordingly.

update: I'm ignoring potential security issues here, since that would make the whole program a lot more complex.

  • Comment on Re: Why is my image obtained by LWP displayed as garbage (i.e. plain/text)?
  • Download Code

Replies are listed 'Best First'.
Re^2: Why is my image obtained by LWP displayed as garbage (i.e. plain/text)?
by crontab (Initiate) on Oct 19, 2005 at 20:16 UTC
    Thank you for responding so quickly. I just tried your suggestion, but unfortunately it didn't work. I *cough* am trying to defeat the corporate firewall (why not, it's motivational for learning perl) and what happens when I try your suggestion is that I see the dratted little red cross which (correct me if I'm wrong) is indicative that the image is being blocked. Or am I wrong? Thanks.

      Disclaimer: I am not advocating that you try to break your company's security policy. They probably have their policy for a reason - and breaking this policy is likely to get you into all kinds of trouble. Think carefully about this before doing it.

      However, in the interests of furthering discussion, if your browser sees the string <img src="/blah"> in a html document, it will attempt to make a separate http request to fetch the image - just as if you tried to type the address into your browser directly. This is therefore being blocked by the relevant firewall.

      To get around this, you need to look at the content_type header that you get back from the remote request (see the earlier post by Joost), and send that content-type back to the browser.

      Actually, to do this *properly* there are other headers that you would need to thing about (authentication and cookies being two good examples that come to mind). What you really want is a proxy server (eg squid, or apache with mod_proxy). However - if you have never set up such a thing before, I'd recommend either getting help, or at least reading the docs quite carefully, as open proxies on the internet are a bad thing (tm)

      defeating the corporate firewall may sound like a fun thing to do but can get you in to loads of trouble. Loss of a job and/or criminal/civil prosecution. It's just not worth the hassle. IMHO

      Jason L. Froebe

      Team Sybase member

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

        loads of trouble
        Last week three of 4 of our young trainees (15-17 years old) got fired. One of them (a darn pretty girl which I would have been glad to welcome in my office (all trainees spend four weeks in the IT department)) has been told the password for the time registration system, to stand in for some colleague who was ill. Unfortately the colleague didn't change the password afterwards...

        And so she happily added hours on the time account of her and two friends. Nobody would have ever noticed it, but out of sheer spite she reduced the account of someone she did not like. Of course that person complained and investigations followed.


        holli, /regexed monk/
        The majority of corporate firewalls are run by morons who would flee in terror at the mere suggestion of scripting or programming languages such as Perl or C.

        Maybe the security staff think they are gurus because they can actually work out an access-list on a Cisco router or *horrors* use Visual Basic in their spare time.

        If you know what you're doing, by passing the corporate firewall is never an unworthy endeavour.

        But I would never, ever contemplate downloading or viewing porn at work. That's a one-way ticket to humiliation and never getting another job.

      If the machine that's running the script is behind the firewall, you probably won't be able to "defeat the firewall" anyway (except see last paragraph).

      IIRC internet explorer will show a red cross i.e. a "red ex" for either unreachable urls AND incorrectly formatted images.

      My suggestion to subvert a firewall would be to use a http proxy. Searching for "anonymous proxy" on a www search engine should give you plenty of results.