Brak has asked for the wisdom of the Perl Monks concerning the following question:
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.
Any advice anyone can provide would be greatly appreciated. Thanks.### 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' );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LWP::UserAgent and correcting automatic redirection.
by Corion (Patriarch) on Nov 09, 2009 at 22:19 UTC | |
|
Re: LWP::UserAgent and correcting automatic redirection.
by gmargo (Hermit) on Nov 09, 2009 at 22:32 UTC | |
by Brak (Novice) on Nov 12, 2009 at 20:26 UTC | |
by gmargo (Hermit) on Nov 12, 2009 at 23:31 UTC |