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

Thanks for adding me to this group. Following is the script and result I am getting:-
use WWW::Mechanize; my $url='https://www.platts.com/Login.aspx?'; my $mechanize = WWW::Mechanize->new(autocheck => 1); $mechanize->cookie_jar(HTTP::Cookies->new); $mechanize->agent('Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1) G +ecko/20061010 (IKDhPmJcdw) Firefox/2.0'); my $response = $mechanize->get( $url ); my $html = $mechanize->content; print "$html \n";
Output of script is:-
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://www.platts.com?">here</a>.</ +p> </body></html>
It should get source page of https://www.platts.com/Login.aspx?, But it is saying error “301 moved permanently”. Can anyone help me please on this regard, I tried a lot but not able to fix this issue? Thanks in advance!

20100128 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: How to avoid "301 moved parmanently " from HTTPS responce?
by JavaFan (Canon) on Jan 28, 2010 at 11:14 UTC
    Seems to work for me, output starts with:
    ^M <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ +/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">^M <html xmlns="http://www.w3.org/1999/xhtml">^M <head><title>^M Platts: Login^M </title>^M ^M <script type="text/javascript" src="JavaScripts/jquery.js"></scrip +t>^M ^M <!---JAVASCRIPT links for Web Trends Tag Implementation--->^M ^M <script type="text/javascript" src="JavaScripts/Webtrends/webtrend +s.js"></script>^M ^M <!---JAVASCRIPT links for Eloqua Tag Implementation--->^M ^M <script type="text/javascript" language="JavaScript" src="elqNow/e +lqCfg.js"></script>^M ^M <script type="text/javascript" language="JavaScript" src="elqNow/e +lqImg.js"></script>^M ^M <!---JAVASCRIPT links for Ad Banner display--->^M <script type="text/javascript" language="JavaScript" src="JavaScri +pts/24X7AdBanner.js"></script>^M
Re: How to avoid "301 moved parmanently " from HTTPS responce?
by WizardOfUz (Friar) on Jan 28, 2010 at 12:37 UTC

    Did you check $mech->redirect_ok()?

Re: How to avoid "301 moved parmanently " from HTTPS responce?
by gmargo (Hermit) on Jan 28, 2010 at 18:02 UTC

    I get the same results as JavaFan.

    By overriding WWW::Mechanize, I determined that I don't get any redirect at all:

    package MyWWWMechanize; use strict; use warnings; use WWW::Mechanize; our @ISA = qw( WWW::Mechanize ); #--------------------------------------------------------------------- +----- # redirect_ok - log redirect messages #--------------------------------------------------------------------- +----- sub redirect_ok { my ($self, $prospective_request, $response) = @_; # Call parent to do all the boring work. my $ok = $self->SUPER::redirect_ok($prospective_request, $response +); # Log it print "Redirect From: ".$response->as_string()."\n"; print "Redirect To: ".$prospective_request->as_string()."\n"; print "Redirect is ".($ok ? "Allowed" : "DENIED")."\n"; return $ok; } 1; package main; my $url='https://www.platts.com/Login.aspx?'; #my $mechanize = WWW::Mechanize->new(autocheck => 1); my $mechanize = MyWWWMechanize->new(autocheck => 1); $mechanize->cookie_jar(HTTP::Cookies->new); $mechanize->agent('Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1) G +ecko/20061010 (IKDhPmJcdw) Firefox/2.0'); my $response = $mechanize->get( $url ); my $html = $mechanize->content; print "$html \n";

    Are you sure you're getting this redirect on a GET and not a POST? Have you messed around with requests_redirectable?