how to use perl to redirect web page?

Discussion in 'Perl Misc' started by Paul, Mar 23, 2007.

  1. Paul

    Paul Guest

    hi, there,

    I am using perl to access specified web pages. this is my code. when I
    run the code, I get the following error: 302 Found. I checked and knew
    this is because of redirect.

    Would you guys tell me how to solve this problem?

    thanks.
    paul.


    use LWP 5.64;
    use LWP::UserAgent;
    use HTTP::Headers;
    use HTTP::Cookies;


    $lurl='http://www.abcddefg.com';
    $lbrowser = LWP::UserAgent->new;
    $lbrowser->timeout(5);
    $lcookie_jar = HTTP::Cookies->new;
    $lreq = new HTTP::Request('GET',$lurl);
    $lresponse = $lbrowser->simple_request($lreq);
    $lcookie_jar->extract_cookies($response);
    if ($lresponse->is_success)
    {
    print "OK. connected with server\n"
    }
    else
    {
    print "Error1: when get $lurl:\t" . $lresponse->status_line . "\n";
    }
     
    Paul, Mar 23, 2007
    #1
    1. Advertising

  2. Paul <> wrote:
    > I am using perl to access specified web pages. this is my code. when I
    > run the code, I get the following error: 302 Found. I checked and knew
    > this is because of redirect.
    > Would you guys tell me how to solve this problem?


    "302 Found" isn't an error. It tells you that the page that
    you requested temporarily resides somewhere else (for whatever
    reasons) and that there's nothing fundamentally wrong. Just go
    to the URI you got told about (in the location field of the
    response) instead. if you don't believe me go to e.g.

    http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

    and look for paragraph 10.3.3. And, by the way, this isn't a
    Perl problem but one of how the HTTP protocol works;-)

    Regards, Jens
    --
    \ Jens Thoms Toerring ___
    \__________________________ http://toerring.de
     
    Jens Thoms Toerring, Mar 23, 2007
    #2
    1. Advertising

  3. Paul

    J. Gleixner Guest

    Paul wrote:
    > hi, there,
    >
    > I am using perl to access specified web pages. this is my code. when I
    > run the code, I get the following error: 302 Found. I checked and knew
    > this is because of redirect.
    >
    > Would you guys tell me how to solve this problem?


    > use LWP::UserAgent;
    > use HTTP::Headers;
    > use HTTP::Cookies;


    use strict;

    >
    >
    > $lurl='http://www.abcddefg.com';
    > $lbrowser = LWP::UserAgent->new;
    > $lbrowser->timeout(5);
    > $lcookie_jar = HTTP::Cookies->new;
    > $lreq = new HTTP::Request('GET',$lurl);
    > $lresponse = $lbrowser->simple_request($lreq);

    [...]

    Check the documentation for LWP::UserAgent.

    perldoc LWP::UserAgent

    You could search for "redirect", to find anything relevant.

    e.g.

    "The difference from request() is that simple_request() will not try
    to handle redirects or authentication responses. "

    Always, always, always, start with the documentation.
     
    J. Gleixner, Mar 23, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,264
    Srowe1975
    Oct 15, 2008
  2. Sal
    Replies:
    1
    Views:
    586
  3. Ron Howard
    Replies:
    2
    Views:
    529
    Ron Howard
    Aug 11, 2004
  4. Replies:
    3
    Views:
    391
  5. johannes falcone
    Replies:
    2
    Views:
    77
    Kevin Walzer
    Feb 1, 2014
Loading...

Share This Page