in reply to Downloading first X bytes of a file
Another way:
using IO::Socket::INET.
This has the advantage to be more flexible.
I don't know what you are looking for in the first 512 bytes, but dependent on what you get you could parse the response and fetch more data if needed.
michael
using IO::Socket::INET.
This has the advantage to be more flexible.
I don't know what you are looking for in the first 512 bytes, but dependent on what you get you could parse the response and fetch more data if needed.
#!/usr/bin/perl -w use strict; use IO::Socket::INET; my $sock = IO::Socket::INET->new(PeerAddr => 'www.google.de', PeerPort => 'http(80)', Proto => 'tcp'); die if ( !$sock ); print $sock "GET http://www.google.de/index.html\n"; my $len = 0; my $file = ''; while ( defined($sock) && ( my $c = $sock->getc()) && ($len<512)){ print $c,"\n\n"; $len+=length $c; $file .= $c; } print $file;
michael
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Downloading first X bytes of a file
by moritz (Cardinal) on Jun 09, 2008 at 12:09 UTC | |
by misc (Friar) on Jun 09, 2008 at 13:00 UTC | |
Re^2: Downloading first X bytes of a file
by tachyon-II (Chaplain) on Jun 09, 2008 at 15:27 UTC | |
by misc (Friar) on Jun 09, 2008 at 18:36 UTC | |
by misc (Friar) on Jun 09, 2008 at 18:35 UTC |
In Section
Seekers of Perl Wisdom