Solved

LWP and Redirect (for example: MOVE)

Posted on 2006-11-29
2
337 Views
Last Modified: 2008-02-01
Hi,

When you sometimes get a page with LWP, it displays a MOVE message,
meaning that the page has been moved. Is it possible for LWP to then get the page on the new address?
i.e: Read and handle 301.

Greeting.
0
Comment
Question by:TonyJix
2 Comments
 
LVL 17

Expert Comment

by:mjcoyne
ID: 18036088
It depends on whether the server provides that information in some manner.  You could check LWP for a 301 error, and branch based on whether it's true or not.  You could then process the page that was returned, looking for the new address.  But, this address might or might not be there, depending on how the server is configured and on what the admin has decided to send on connect to the old address.  Moreover, if the re-direct page does provide the new address, it could be anywhere on the page, and is not garunteed to be the only URL on the page...
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 18036248
require LWP::UserAgent;
 
 my $ua = LWP::UserAgent->new;
 
 $ua->max_redirect( 7 );

 my $response = $ua->get('http://search.cpan.org/');
 
 if( $response->is_success ){
     print $response->content;  
 }else{
     die $response->status_line;
 }
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now