I have a script that reads one of my pages to test it. the page it tests, will redirect to a number of different urls.
I use LWP to contact the page and get me the html of the page it loads. Some of them are identical source code.
I need to know what URL it is redirecting to.
How can I get that from LWP?
Here is my code:
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/8.0");
$ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt",
autosave => 1));
push @{$ua->requests_redirectable}, 'GET';
my $req = HTTP::Request->new(GET => "$_fileLoc");
$req->referer($_fileLoc);
# Pass request to the user agent and get a response back
$res = $ua->request($req);
print $res->status_line, "\n";
if($res->status_line =~ /404 Not Found/i) {
$_bad++;
} else {
if($res->is_success) {
print $res->is_success, "\n";
if($res->status_line =~ /404 Not Found/i) {
$_bad++;
} else {
$_cn = $res->content;
print $_cn, "\n";
}
} else {
$_bad1++;
$_errorT = $res->status_line;
print qq~error: "~ . $_errorT . '"'. \t;#'
}
}
that is a section of my code.
How can I get this to only tell me the URL it redirected to? not the url it ended up on, but where it redirected to, like this:
header("Location: http://mydomain.com/path1/someotherpath.php");
have it give me the redirected url: http://mydomain.com/path1/someotherpath.php, because
someotherpath.php would also redirect to one other location, so I need the first one.
Can someone tell me how to do this?
Thank you.
Richard
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.