in reply to HTTP status codes

Do you want it to be silent for the redirection? Use a simple_request instead of request.

my $ua = LWP::UserAgent->new; my $uri = shift @ARGV; my $headreq = HTTP::Request->new(HEAD => $uri); my $headres = $ua->simple_request($headreq); # <---- my $statuscode = $headres->code(); print "Status 401 at $uri\n" if $statuscode == 401;

Or do you wish for it to display the uri to which you were redirected? Access it through the Request that produced the Response.

my $ua = LWP::UserAgent->new; my $uri = shift @ARGV; my $headreq = HTTP::Request->new(HEAD => $uri); my $headres = $ua->request($headreq); my $statuscode = $headres->code(); if ($statuscode == 401) { my $final_uri = $headres->request()->uri(); # <---- print "Status 401 at $final_uri\n" }

Replies are listed 'Best First'.
Re^2: HTTP status codes
by memwaster (Initiate) on Oct 30, 2007 at 10:47 UTC
    Thank you both for your answers. I think I will use ikegami's second option to display the uri to which I am redirected and filter out any https:// results later. If I ignore redirections completely there might be some false negatives.

    cheers

    memwaster