I've got this script which uses LWP::UserAgent to connect to and receive data from a server which is not managed by me. It's managed by a department at my organization that doesn't really understand how to or doesn't want to fix minor internal issues. Therefore, I'm sort of stuck with having to deal with their... ignorance.

The Scenario
I have an initial URL. It's a fully qualified absolute URL like the documentation wants. However, the server 302-forwards the request to a relative URI, then gets mad because it's not an absolute URI.

The Question
How can I intercept the 302 request before it's sent back to LWP::UserAgent, so I can prepend the server's domain, which will make it a fully qualified absolute URI that the server won't bark at. If it's possible to not manually issue the redirect request, I'd be super happy.

The Response
So below is the output from Dumper() of my $ua User Agent object. I create some POST values, all basic ones, simple strings, and pass them to my initial URI and initiate the request to the server. The server responds with a 302 File moved response, pointing to a relative URI. (The initial request *must* be made to that URI and it *must* be forwarded to the secondary URI, as the first URI generates a session variable for the second one.) LWP picks this response up and re-issues the command to the new location, however, the server doesn't like the relative URL and wants an absolute URL instead. So it instead of returning the desired/intended response, it complains kicking back the 400 error "URL must be absolute". The process works as expected when run in a traditional web browser. I believe the reason it works at all is because the browser is actually fixing the URL from the Location header before issuing the redirect request. Probably doing this to be more tolerant of non-standard-compliant code.

### This is a dump of my LWP::UserAgent object ### ### It looks like the '_uri' has the incomplete relative ### URI in it. The script on the server is named 'f' and ### it has some query string args. ## Headers $VAR1 = bless( { 'client-warning' => 'Internal response', 'client-date' => 'Mon, 09 Nov 2009 20:43:38 GMT', 'content-type' => 'text/plain' }, 'HTTP::Headers' ); ## Content $VAR1 = '400 URL must be absolute '; $VAR1 = bless( { '_content' => 'p_v03=AUACB&p_flow_id=145&p_flow_step_ +id=12&p_request=GO&p_t04=&p_instance=3135116688739984&p_md5_checksum= +&p_arg_names=2162829369140202&p_t01=CF&p_t02=2010', '_uri' => bless( do{\(my $o = 'f?p=145:12:31351166887 +39984:::::')}, 'URI::_generic' ), '_headers' => bless( { 'user-agent' => 'MyOrganizatio +nHere/WebGrabber (ScreptNameHere / Perl 5.008008)', 'content-type' => 'application +/x-www-form-urlencoded', 'content-length' => 156, 'authorization' => 'Basic AnAU +THENTICATIONhashHERE ' }, 'HTTP::Headers' ), '_method' => 'POST' }, 'HTTP::Request' ); $VAR2 = bless( { '_content' => '400 URL must be absolute ', '_rc' => 400, '_headers' => bless( { 'client-warning' => 'Internal +response', 'client-date' => 'Mon, 09 Nov +2009 20:43:38 GMT', 'content-type' => 'text/plain' }, 'HTTP::Headers' ), '_msg' => 'URL must be absolute', '_request' => $VAR1 }, 'HTTP::Response' );
Any advice anyone can provide would be greatly appreciated. Thanks.

In reply to LWP::UserAgent and correcting automatic redirection. by Brak

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.