Vickie Cooper <[EMAIL PROTECTED]> writes:
>I want to write a webpage to a file and if I use:
>
>use IO::Socket;                                                        
>
>my $http_cmd = "GET /mytest.html HTTP/1.0\n\n";                        
>
>my $run_cmd = `echo '$http_cmd'`; 
>
>my $S = IO::Socket::INET->new( PeerAddr => $ARGV[0] || "localhost",
>
>
>                               PeerPort => $ARGV[1] || 80,             
>
>                               Proto => "tcp",                         
>
>                               Type => SOCK_STREAM) or die $@;         
>
>send $S, $run_cmd, 0 or die "send: $!\n";                            
>
>shutdown $S, 1;                                                        
>
>sysread $S, $_, 1024, 0 or die "recv: $!\n";             
>
>@webpage=<$S>;
>
>print @webpage;
>
> 
>
>At this point I get the last part of the webpage (probably the last 1024
>bytes).  If I change the 1024 to 1, then it looks like I get the entire
>page in the array.  Does this read 1024 bytes into $S?  Do I have to do
>some type of a loop to get the entire stream?  Why do I get the entire
>stream if I change it to 1 or 10?

sysread is reading byte count you requested from $S into $_ - using unbuffered
IO. 

Then you read "rest" of data via <$S> a line per entry into @webpage
using buffered IO.

I don't think you need the sysread at all. 

You will get web page + HTTP headers in @webpage though.

LWP module has higher level calls that will strip those for you
(and also follow redirects etc.)




>
> 
>
>Thanks,
>
> 
>
>Vickie Cooper
>
> 
>
>Vickie Cooper
>OS/390 Web Services & FOCUS/EDA Technical Support
>Phone: (425) 957-5502
>Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 

Reply via email to