tmbg has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to automate a session with some nasty cold-fusion done pages using LWP::UserAgent, and I've run across an interesting problem

using the full fledged request method, it will perform all necessary redirections for you if it can. This is happening, and I'm ending up on a page which is not the page I requested (obviously).

so, now that I've got my $page object returned from $ua->request($req), how can I get it to tell me what the ACTUAL URL of the page I'm seeing is?

Replies are listed 'Best First'.
Re: LWP::UserAgent redirection troubles
by merlyn (Sage) on May 02, 2001 at 19:45 UTC
    perldoc HTTP::Response says:
    $r->base Returns the base URI for this response. The return value will be a reference to a URI object. The base URI is obtained from one the following sources (in priority order): 1. Embedded in the document content, for instance <BASE HREF="..."> in HTML documents. 2. A "Content-Base:" or a "Content-Location:" header in the response. For backwards compatability with older HTTP imple- mentations we will also look for the "Base:" header. 3. The URI used to request this response. This might not be the original URI that was passed to $ua->request() method, because we might have received some redirect responses first. When the LWP protocol modules produce the HTTP::Response object, then any base URI embedded in the document (step 1) will already have initialized the "Content-Base:" header. This means that this method only performs the last 2 steps (the content is not always available either).

    -- Randal L. Schwartz, Perl hacker

      Perfect.

      One more silly question, if I may:

      What does this mean:

      Unexpected field value https://www.banko.com/login/Applications/docketsondemand/Basket/index.cfm?cfid=25416&cftoken=5496817&end_tag=22891870&CFID=25416&CFTOKEN=5496817 at /usr/lib/perl5/site_perl/HTTP/Message.pm line 189

      Thanks a lot!

Re: LWP::UserAgent redirection troubles
by tomhukins (Curate) on May 02, 2001 at 19:49 UTC

    Your $ua->request($req) returns an HTTP::Response object, according to the documentation for LWP::UserAgent.

    The base method in HTTP::Response does what you want. Here is some example code, without any error checking though:

    my $response = $ua->request($req); # Assumes $req is an HTTP::Request + object print $response->base;