in reply to Re: WWW::Mechnize redirect handling
in thread [Solved] WWW::Mechnize redirect handling

Hi and thanks for your reply. I tried that (a minute ago), but the response stays the same.

Replies are listed 'Best First'.
Re^3: WWW::Mechnize redirect handling
by bliako (Abbot) on Nov 22, 2019 at 19:55 UTC

    can you show the code? and the response?

      Yes, of course, but I've just changed:

      $m->max_redirect(2);

      to:

      $m->max_redirect(0);

      On a closer look, the result is not entirely the same but also not much better (redirect loop detected):

      Cache-Control: no-cache, no-store, max-age=0, must-revalidate Date: Fri, 22 Nov 2019 22:25:09 GMT Pragma: no-cache Via: url Server: servername Vary: Accept-Encoding,Origin Content-Encoding: gzip Content-Language: en Content-Length: 6336 Content-Type: text/html;charset=UTF-8 Expires: 0 Client-Date: Fri, 22 Nov 2019 22:29:13 GMT Client-Peer: xxx.xxx.xxx.xxx:443 Client-Response-Num: 1 Client-SSL-Cert-Issuer: /certinfo Client-SSL-Cert-Subject: /certinfo Client-SSL-Cipher: ECDHE-RSA-AES256-GCM-SHA384 Client-SSL-Socket-Class: IO::Socket::SSL Client-SSL-Warning: Peer certificate not verified Client-Warning: Redirect loop detected (max_redirect = 0) Strict-Transport-Security: max-age=15768000 ; includeSubDomains Strict-Transport-Security: max-age=15768000 X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 1; mode=block

      Strange, isn't it?

        Change that user-agent string to something valid instead of myagent.

        When I hit facebook with that script I get a Location header item as expected.

        Regarding autocheck=>1, from WWW::Mechanize manpage:

        Checks each request made to see if it was successful. This saves you t +he trouble of manually checking yourself. Any errors found are errors +, not warnings.

        Setting max_redirect=0 is good for making sure things work and gives you all control. But there is an easier way to do it:

        $m->max_redirect(3); # whatever redirects you may thing you will get o +r more my $content = $m->post($uri); my $ri=0; foreach my $aredirect ($content->redirects()){ $ri++; print "REDIRECT $ri ******\n".($aredirect->as_string())."\nEND + ****\n\n"; }

        That is, you loop through the headers of each of the redirects encountered to get what you need and at the same time you are at your final URL to hit login.

        bw, bliako