#!/usr/bin/perl use warnings; use strict; use WWW::Curl::easy; # Read URL to get my $url = "http://zentara.zentara.net/~zentara/cgi-bin/avi-out.cgi"; # Init the curl session my $curl = WWW::Curl::easy->new(); if ($curl == 0) {print "not ok $!\n "} $curl->setopt(CURLOPT_NOPROGRESS, 0); $curl->setopt(CURLOPT_FOLLOWLOCATION, 1); sub prog_callb{ my ($clientp,$dltotal,$dlnow,$ultotal,$ulnow)=@_; my $percentage = ($dlnow/$dltotal)*100; print STDERR "dltotal: $dltotal, dlnow: $dlnow\t", sprintf("%.0f",$percentage),"% complete\n"; return 0; } $curl->setopt(CURLOPT_PROGRESSFUNCTION, \&prog_callb); open HEAD, ">$0-head.out"; $curl->setopt(CURLOPT_WRITEHEADER, *HEAD); open BODY, ">$0-body.out"; $curl->setopt(CURLOPT_FILE,*BODY); $curl->setopt(CURLOPT_URL, $url); # Add some additional headers to the http-request: #my @myheaders; #$myheaders[0] = "Server: www"; #$myheaders[1] = "User-Agent: Perl interface for libcURL"; #$curl->setopt(CURLOPT_HTTPHEADER, \@myheaders); # Go get it my $retcode=$curl->perform(); if ($retcode == 0) { my $bytes = $curl->getinfo(CURLINFO_SIZE_DOWNLOAD); print STDERR "$bytes bytes read "; my $realurl=$curl->getinfo(CURLINFO_EFFECTIVE_URL); my $httpcode=$curl->getinfo(CURLINFO_HTTP_CODE); print STDERR "effective fetched url (http code: $httpcode) was: $url "; } else { # We can acces the error message in $errbuf here print STDERR "$retcode / ".$curl->errbuf."\n"; } exit;