Hi,

  I run a free service for General Aviation pilots to put  weather data 
  on their mobile phones. One site of use to UK pilots is the UK Met 
  Office but their logon pages are tedious and have a high bandwidth 
  overhead for mobile users.
 
  I am trying to provide a 'proxy' service that requests an image on 
  behalf of a user and returns it to their mobile without caching the 
  image on my server. (Caching would break the conditions of site-use 
  imposed by the met office).
 
  I am able to return HTML content to a user but gif images have so far 
  defeated me.
 
 
  My current code iteration looks like this:-
 
  #!/www/perl/bin/perl.exe # sorry guys Windows XP server!
   use LWP::UserAgent;
   use CGI;
   use HTTP::Cookies;
   use CGI::Carp qw/fatalsToBrowser/;
 
   my $query = CGI- new();
  my $username=$query- param('username');
  my $password=$query- param('password');
 
    my $ua = LWP::UserAgent- new;
      my $req = HTTP::Request- new(GET =  
  "http://secure.metoffice.com/logon.do?
  username=$username&password=$password&submitted=&submit=logon");
      $req- referer("http://www.activitae.com";);
    my $res = $ua- request($req);
    my $cookie_jar = HTTP::Cookies- new(
                     File     =  "$ENV{HOME}/cookies",
                     AutoSave =  1,
                                       );
      $cookie_jar- extract_cookies($res);
 
      my $id = $res- {'_headers'}- {'set-cookie'}- [10];
    if ($res- is_success) {
   # for testing only
        #print $res- as_string;
        #print $id;
    } else {
        print "Failed: ", $res- status_line, "\n";
    }
    # alternate lines for testing
    #my $secreq = HTTP::Request- new(GET =  
  'http://secure.metoffice.com/aviation/reports.do?type=METAR&list=04');
  #
  returns html
    my $secreq = HTTP::Request- new(GET =  
  'http://secure.metoffice.com/aviation/productcomponentserver.do?
  productId=157&componentId=0&imageFile=F215_1824.gif');
  # returns gif
 
     $secreq- referer(http://www.activitae.com);
     $cookie_jar- add_cookie_header($secreq);
 
    my $secres=$ua- request($secreq);
    if ($secres- is_success) {
      print "HTTP/1.0 \r\n";
      print "Content-Type: image/gif\r\n";
       print "Connection: close\r\n\r\n";
 
       binmode print $secres- {'_content'};
      exit 0;
    } else {
        print "Failed: ", $secres- status_line, "\n";
    }
 
  Firstly the code does a remote logon for a user and gets a session ID, 
  then second request for the image of weather data is made.  When run 
  via the development environment of Komodo text headed by GIF87 is 
  returned.
  When the
  alternate line for $secreq is used good html is returned.
 
  However, when both alternatives are run, a server error 'premature end 
  of script errors' is reported.
 
  Any pointers to the correct way of doing things will be greatly 
  appreciated!
 
  Angela



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to