Solved

LWP and Redirect (for example: MOVE)

Posted on 2006-11-29
2
342 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Removing file extension within a file. 4 98
Perl passing in variables to do substitution 6 75
Perl modules on linux ec2 3 114
Log File Creation with Header and Footer 17 126
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

856 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