Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: WWW::Mechnize redirect handling

by bliako (Monsignor)
on Nov 22, 2019 at 19:55 UTC ( [id://11109077]=note: print w/replies, xml ) Need Help??


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

can you show the code? and the response?

Replies are listed 'Best First'.
Re^4: WWW::Mechnize redirect handling
by nikster (Novice) on Nov 22, 2019 at 22:33 UTC

    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

        I've inserted your code into my script.

        But the response is exactly the same as the one I've posted before.

        If I try against facebook, like you did, I get all the redirect headers.

        Must be something about the site itself, unfortunately there is no one to ask.

        Thank's very much, though!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11109077]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found