1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
my $url = "http://url.domain.com/";
$url=~m/http\:\/\/([^\:^\/]*)(?:\:(\d+))?\/(.*)/;
my $host = $1;
my $port = $2;
$port = 80 unless($port);
my $file = '/'.$3;
my $proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto);
my $sin = sockaddr_in($port, inet_aton($host));
connect(SOCK, $sin) || die "Connect failed: $!\n";
my $old_fh = select(SOCK);
$|=1;
select($old_fh);
print SOCK "GET ".$file." HTTP/1.1\n";
print SOCK "Host: ".$host."\n";
print SOCK "Accept: */*\n";
print SOCK "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; fr; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3\n";
print SOCK "Connection: close\n";
print SOCK "Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3\n\n";
my ($content, $headers, $line, $temp, $b) = ("", "", "", 0, 1);
while($line = <SOCK>) {
chomp($line);
# Ignore les lignes vides
$line =~ /^\s*$/ && next;
# $content contient le contenu
$content = $content.$line;
}
print $content; |
Partager