#!/usr/bin/perl -w
use strict;

use Curl::easy;

my $url = "http://www.example.com/auth";

my $curl = Curl::easy->new();

$curl->setopt(CURLOPT_NOPROGRESS, 1);
$curl->setopt(CURLOPT_MUTE, 1);

$curl->setopt(CURLOPT_URL, $url);

reload:
if ($curl->perform() == 0) {
    my $httpcode;
    $curl->getinfo(CURLINFO_HTTP_CODE,$httpcode);
    if ($httpcode == 401) {
	$curl->setopt(CURLOPT_USERPWD, "user:pass");
	goto reload;
    }
}

exit;

