-----Original Message-----
From: Smith, Stephen (ELS) 
Sent: 12 February 2001 09:06
To: 'Steve Sotis'
Subject: RE: LWP / Port
Importance: High


Try this:

Regards 
Stephen Smith
(Senior Developer Reed Elsevier)

    sub Http_Download
    {
      local ( $METHOD ) = shift ;
      local ( $URL ) = shift ;
      local ( $filename ) = shift ;

      my $base = $build_dir."dwnload/" ;
      my $EOL = "\015\012" ;
      my $hisiaddr = $URL ;

      # Define Port you want to use
      my $port = 80 ;
      my ($content_length, $hispaddr, $http_req) ;

      $hisiaddr =~ tr/[A-Z]/[a-z]/ ;
      $hisiaddr =~ s/http:\/\///g ;

      my ( $host ) = (split('/', $hisiaddr))[0] ;
      my $page = $URL ;
      $page =~ tr/[A-Z]/[a-z]/ ;
      $page =~ s/http:\/\///g ;
      $page =~ s/$host//g ;

 
      $hisiaddr = inet_aton($host) || give_up("unknown host") ;
      $hispaddr = sockaddr_in($port, $hisiaddr) ;
      socket(SOCKET, PF_INET, SOCK_STREAM, $proto)   || give_up("socket:
$!") ;
      connect(SOCKET, $hispaddr) || give_up("unknown host ($host)") ;

      # --- Create download area and open file to receive data

      Create_Dir($base) ;
      $base = $base . $filename ;
      $base =~ tr /[A-Z]/[a-z]/ ;
      unlink $base ;

      my $file_out = File_Create($base) ;             # --- Create Article
file

      # --- Setup Http 1.1 Request Headers

      $http_req = $METHOD." ".$page." HTTP/1.1\n" ;
      $http_req = $http_req . "Referer: http://". $hostname . "\n" ;
      $http_req = $http_req . "User-Agent: Mozilla/4.0 (compatible ; MSIE
4.0 ; Windows 98 ; Oasis Download WebApps)\n" ;
      $http_req = $http_req . "Content-Type: text/html\n" ;
      $http_req = $http_req . "Cache-control: private\n" ;
      $http_req = $http_req . "Host: $host\n\n" ;

      # --- Send Http 1.1 Request

      send(SOCKET, $http_req, 0) ;

      # --- Get Reply

      $http_req = <SOCKET> ;
      if($http_req =~ m@^HTTP/\d+\.\d@)
      {
        $http_req =~ s/$EOL//g ;
        $http_req =~ s/^M//g ;
        until ($http_req =~ /^\015?\012/ || $http_req =~
/\015?\012\015?\012/)
        {
          if ($http_req =~ /Content-Length/)
          {
            $content_length = $http_req ;
            $content_length =~ s/Content-Length://g ;
            $content_length =~ s/ //g ;
            $content_length =~ s/$EOL//g ;
          }
          $http_req =~ s/\n//gs ;
          $http_req =~ s/\r//gs ;
          $http_req =~ s/^M//g ;
          $http_req = <SOCKET> ;
        }
      }
      $host = $port = 0 ;

      while(<SOCKET>)
      {
        $http_req = $_ ;
        $port = $port + length($http_req) ;
        $hispaddr = $content_length - $port ;

        $http_req =~ s/$EOL//g ;
        if(http_req eq "" || $port >= $content_length)
        {
          close(SOCKET) ;
          $host = 1 ;
        }
        if($host == 0)
        {
          $http_req =~ s/$EOL//g ;
          $http_req =~ s/^M//g ;
          $http_req =~ s/\n//gs ;
          $http_req =~ s/\r//gs ;
          $http_req =~ s/^M//g ;
          print $file_out $http_req,"\n" if($http_req ne $EOL) ;
        }
      }
      close(SOCKET) if ($host==0) ;
      close $file_out ;
      undef $file_out ;
    } # End Sub

do not forget to add your own give_up message handler

-----Original Message-----
From: Steve Sotis [mailto:[EMAIL PROTECTED]]
Sent: 11 February 2001 22:09
To: [EMAIL PROTECTED]
Subject: LWP / Port


I will need to start communicating with a server via a non-standard port in 
the next week or so, and in preparation, I stopped by the LWP reference to 
see if anything about ports was mentioned. NOT!

And, there will be no URL for me to access, just an IP.

Can I use an IP/Port with LWP, i.e. '1.2.3.4:123' for the request object?

Is there anything special I would need for the content_type?

Is there a better alternative to LWP?

TIA!

Steve


_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to