#!/usr/bin/perl -- use strict; use warnings; use WWW::Mechanize 1.54; my $ua = WWW::Mechanize->new; $ua->add_handler("request_send", sub { $_[0]->content(''); $_[0]->dump; return }); $ua->add_handler("response_done", sub { $_[0]->content(''); $_[0]->dump; return }); my $uri = URI->new('http://jigsaw.w3.org/HTTP/Basic/'); $ua->credentials( $uri->host_port, qw' test guest guest '); $ua->get( $uri ); print "\n--- SPECIFY HOST MANUALLY ---\n"; my $host = $uri->host( $ua->res->header('Client-peer') ); $ua->get( $uri, Host => $host ); __END__ GET http://jigsaw.w3.org/HTTP/Basic/ Accept-Encoding: gzip User-Agent: WWW-Mechanize/1.66 (no content) HTTP/1.1 401 Unauthorized Connection: close Date: Tue, 05 Oct 2010 10:07:17 GMT Server: Jigsaw/2.3.0-beta2 WWW-Authenticate: Basic realm="test" Content-Length: 261 Content-Type: text/html;charset=ISO-8859-1 Client-Date: Tue, 05 Oct 2010 10:07:20 GMT Client-Peer: 128.30.52.72:80 Client-Response-Num: 1 Title: Unauthorized (no content) GET http://jigsaw.w3.org/HTTP/Basic/ Accept-Encoding: gzip Authorization: Basic Z3Vlc3Q6Z3Vlc3Q= User-Agent: WWW-Mechanize/1.66 (no content) HTTP/1.1 200 OK Connection: close Date: Tue, 05 Oct 2010 10:07:17 GMT ETag: "1lkdfte:qoguo8q8" Server: Jigsaw/2.3.0-beta2 Content-Length: 458 Content-Location: http://jigsaw.w3.org/HTTP/Basic/ok.html Content-Type: text/html Last-Modified: Sun, 25 Jun 2000 17:08:58 GMT Client-Date: Tue, 05 Oct 2010 10:07:20 GMT Client-Peer: 128.30.52.72:80 Client-Response-Num: 1 Title: Basic Authentication test page (no content) --- SPECIFY HOST MANUALLY --- GET http://128.30.52.72:80/HTTP/Basic/ Accept-Encoding: gzip Host: jigsaw.w3.org Referer: http://jigsaw.w3.org/HTTP/Basic/ User-Agent: WWW-Mechanize/1.66 (no content) HTTP/1.1 401 Unauthorized Connection: close Date: Tue, 05 Oct 2010 10:07:18 GMT Server: Jigsaw/2.3.0-beta2 WWW-Authenticate: Basic realm="test" Content-Length: 261 Content-Type: text/html;charset=ISO-8859-1 Client-Date: Tue, 05 Oct 2010 10:07:20 GMT Client-Peer: 128.30.52.72:80 Client-Response-Num: 1 Title: Unauthorized (no content) Error GETing http://128.30.52.72:80/HTTP/Basic/: Unauthorized at test.pl line 20