Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to use perl to redirect web page?

Reply
Thread Tools

how to use perl to redirect web page?

 
 
Paul
Guest
Posts: n/a
 
      03-23-2007
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";
}

 
Reply With Quote
 
 
 
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      03-23-2007
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
 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      03-23-2007
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How do I use web.config to redirect pages? Henry Stock ASP .Net 0 07-26-2010 02:25 AM
Response.redirect does not redirect from .aspx page =?Utf-8?B?VHJveQ==?= ASP .Net 3 10-15-2008 09:07 PM
Redirect to secure FTP site via response.redirect Ron Howard ASP General 2 08-11-2004 07:40 PM
Basic Q - Response.Redirect, all redirect to first Response.Redirect statement Sal ASP .Net Web Controls 1 05-15-2004 03:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57