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

If you do an $rc = getstore("http://www.voltar.org/sky", "somthing"); LWP::Simple does a 302 redirect behind your back. is_redirect( $rc ); will be false, but if you were to telnet the port directly, you'd get a 302 to "http://www.voltar.org/sky/".

How can I detect that 302, or at least get the URI it goes to so I can build the relative URIs from the page?

  • Comment on LWP::Simple relative URI bad bad bad. ;)

Replies are listed 'Best First'.
Re: LWP::Simple relative URI bad bad bad. ;)
by chipmunk (Parson) on Nov 03, 2001 at 02:22 UTC
    What you want to do is too complicated for LWP::Simple. :) At this point you should switch to LWP::UserAgent, HTTP::Request, and HTTP::Response, to get more control over your requests and how you handle the responses. In addition to those modules, the LWP bundle also comes with the lwpcook documentation, which contains lots of examples for LWP.
Re: LWP::Simple relative URI bad bad bad. ;)
by joealba (Hermit) on Nov 03, 2001 at 01:19 UTC
    Actually, it's the webserver that sends the 302 to the proper directory path (if it finds that "sky" is truly a directory and not the filename of some other type of file). It's now LWP's fault.

    If you type the URL of a directory without the trailing slash, the webserver has to redirect to that directory and then invoke the default handlers (like Apache's DirectoryIndex or MultiViews directives).

    And to answer your question, check out LWP.pm docs:

    • Supports transparent redirect handling

    Oops... Doesn't that suck.


    Updated: Added that last part afterwards, because I was motivated enough to look it up for ya. :)

      How can I detect it? As I work around, I could alwayNet::TCP the port and get it, but that seems sloppy if I'm already using LWP...

      ... I guess from what you're saying that's how I'll have to do it...