Mike Trinder wrote:
> 
> I need to open a HTTP connection to a local machine, get the
> response data (a JPEG image) and then pass that on to the client
>  - this is necessary as (1) the images are stored on a computer
> that is not visible publically and (2) I need to check that the
> client is authorised to see a particular image before returning
> it.
> 
> As a standalone Perl script, this works fine:
> 
> use Win32::Internet;
> print "Content-type: image/jpeg\r\n\r\n";
> 
>         $theURL = 'http://an.IP.addr.ess/lib/foo.jpg';
> 
>         $Connection = Win32::Internet->new();
>         $file = $Connection->FetchURL($theURL);
> 
>         binmode( STDOUT );

You also need to binmode on the FetchURL (unless it does it for you).

>         print $file;
> 
> But I have to run the code from within an ASP page as the username
> and password for access are stored in Session variables.
> 
> This doesn't work at all - I get a zero byte content-length:
> 
> <%@ Language=PerlScript %><%
> 
> use Win32::Internet;
> use Win32::OLE;
> 
> $Connection = Win32::Internet->new();
> 
>         $Response->{Buffer} = 1;
>         $Response->Clear;
>         $Response->{ContentType} = 'image/jpeg';
> 
>         $file = $Connection->FetchURL('http://an.IP.addr.ess/lib/foo.jpg');
>         $Response->BinaryWrite(Win32::OLE::Variant->new( VT_UI1, $file ));
> 
>         $Response->End;
> 
> %>
> 
> Interestingly, just $Response->BinaryWrite($file); gives me _a_ response,
> but it is pretty garbled (it has an extra 16 bytes at the start, and
> is about 1/10th of the correct length). Now, I've read enough to
> know why writing the file directly won't work, but I don't understand
> why I'm not getting a response at all.
> 
> The JPEG in question is c. 192K (so I should be reading and writing
> chunks, but I can't get that to work in ASP either :()
> 
> I'm going mad here...

I would suggest you use LWP to fetch the image (or even use sockets).
LWP is more portable too.

use LWP::Simple;
my $url = 'http://somehost/some.gif';
my $content = &get ($url);
binmode STDOUT;
print $content;

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.wgn.net/~dbe/
  / ) /--<  o // //      Mailto:[EMAIL PROTECTED]   http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to