#!perl # Test script for Perl extension Curl::easy. # Check out the file README for more info. use strict; use Curl::easy; # my $url = "http://curl.haxx.se/dev/"; my $url = "https://www.microsoft.com/"; print "Testing curl version ",Curl::easy::version(),"\n"; # Init the curl session my $curl= Curl::easy->new() or die "curl init failed!\n"; # Follow location headers $curl->setopt(CURLOPT_FOLLOWLOCATION, 1); $curl->setopt(CURLOPT_SSL_VERIFYPEER, 0); # Add some additional headers to the http-request: my @myheaders=( "I-am-a-silly-programmer: yes indeed you are", "User-Agent: Perl interface for libcURL" ); $curl->setopt(CURLOPT_HTTPHEADER, \@myheaders); $curl->setopt(CURLOPT_URL, $url); sub body_callback { my ($chunk,$context)=@_; push @{$context}, $chunk; return length($chunk); # OK } $curl->setopt(CURLOPT_WRITEFUNCTION, \&body_callback); my @body; $curl->setopt(CURLOPT_FILE, \@body); if ($curl->perform() != 0) { print "Failed ::".$curl->errbuf."\n"; }; # # Cleanup is automatic # print join("",@body);