#!/usr/bin/perl
use strict;
use utf8;
use LWP::UserAgent;
use HTTP::Request             qw();
use URI                       qw();
#use URI::Escape               qw(uri_escape);
use Net::IDN::Encode        qw(domain_to_ascii);

my ($CFG, $File);

my $ua = new LWP::UserAgent;
$ua->env_proxy();
$ua->parse_head(0);  # Don't parse the http-equiv stuff.

$ua->protocols_allowed(['http', 'https']);
my @uris = ("http://www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp", "http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp/", 
"http://www.sw.it.aoyama.ac.jp/Dürst/");

foreach my $uri (@uris) {
    print "before URI construction: ", $uri, "\n";
    my $uri_clean = new URI($uri);
    print "URI object:", $uri_clean,  "\n";
    $uri_clean->host( domain_to_ascii($uri_clean->host) );
    print "URI object after domain_to_ascii:", $uri_clean,  "\n";
    $uri_clean = $uri_clean->canonical();
    print "URI object after canonical:", $uri_clean,  "\n";
    print "sending request... ";
    my $req = new HTTP::Request(GET => $$uri_clean);
    $req->header(Cache_control=> "max-age=0");
    my $res = $ua->request($req);
    unless ($res->code == 200){
       print "\n ERROR ", $res->code, " ", $res->message;
    }
    print "\n\n";
}

