<?xml version="1.0" encoding="windows-1252"?>
<node id="1008147" title="LWP Question" created="2012-12-10 13:34:29" updated="2012-12-10 13:34:29">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
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.&lt;br /&gt;
&lt;br /&gt;
I use LWP to contact the page and get me the html of the page it loads. Some of them are identical source code.&lt;br /&gt;
&lt;br /&gt;
I need to know what URL it is redirecting to.&lt;br /&gt;
How can I get that from LWP?&lt;br /&gt;
&lt;br /&gt;
Here is my code:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;

	my $ua = LWP::UserAgent-&gt;new;
	$ua-&gt;agent("Mozilla/8.0");
	$ua-&gt;cookie_jar(HTTP::Cookies-&gt;new(file =&gt; "lwpcookies.txt",
                                     autosave =&gt; 1));
	
	push @{$ua-&gt;requests_redirectable}, 'GET';
	my $req = HTTP::Request-&gt;new(GET =&gt; "$_fileLoc");
	$req-&gt;referer($_fileLoc);
  # Pass request to the user agent and get a response back
	$res = $ua-&gt;request($req);
	print $res-&gt;status_line, "\n";
	if($res-&gt;status_line =~ /404 Not Found/i) {
		$_bad++;
	} else {
		if($res-&gt;is_success) {
			print $res-&gt;is_success, "\n";
			if($res-&gt;status_line =~ /404 Not Found/i) {
				$_bad++;
			} else {
				$_cn = $res-&gt;content;
				print $_cn, "\n";
			}
		} else {
			$_bad1++;
			$_errorT = $res-&gt;status_line;
			print qq~error: "~ . $_errorT . '"'. \t;#'
		}
	}
&lt;/code&gt;

that is a section of my code.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Can someone tell me how to do this?&lt;br /&gt;
&lt;br /&gt;
Thank you.&lt;br /&gt;
&lt;br /&gt;
Richard</field>
<field name="reputation">
7</field>
</data>
</node>
