In the general case, you can backtrack the response chain using the previous method for HTTP::Response objects. I got a lot of help in this example from the GET script that comes with LWP:
use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $url = "http://imdb.com/find?nm=on;mx=20;q=eliza%20dushku"; my $response = $ua->get($url); my @chain = ( $response ); while ( $chain[0]->previous ) { unshift @chain, $chain[0]->previous; } for (@chain) { printf "%s %s --> %s\n" => $_->request->method, $_->request->url->as_string, $_->status_line; } __END__ GET http://imdb.com/find?nm=on;mx=20;q=eliza%20dushku --> 302 Found GET http://imdb.com/name/nm0244630/ --> 200 OK
For your purposes, it's probably simpler to just compare the URL of the final HTTP::Response object with the one you gave to the UserAgent. If they're different, you must have encountered some sort of redirect:
my $response = $ua->get($url); if ( $response->request->url->as_string ne $url ) { ... }

blokhead


In reply to Re: How to tell if a URL returned a Location: header? by blokhead
in thread How to tell if a URL returned a Location: header? by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.