Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi there,
I want to logon to a secure site which is using https and a secure certificate.
My script doesn't return any error, but I can't log in. After I submitted the form using my code, I get a html-site that's telling my "Username or password wrong...".
But username and passwort is correct. If I copy and paste from my script to the corresponding fields in a browser and submit the form, it works fine.

Here the shortened HTML-Form of my site ' https://mySite.de/admin ':
<form action="/admin/index.php?action=login" method="post" name="actio +n"> <input type="hidden" name="ADMIN" value="f23af307ea00b284fb9e74c4cb +abfbdf" /> <input type="text" name="username" size="12" value=""> <input type="password" name="password" size="12"> <input type="submit" name="login" value="Login"> </form>

Here my script:
01: use WWW::Mechanize; 02: use LWP::Debug qw(+); 03: 04: $username = "xxx"; 05: $password = "xxx"; 06: 07: my $mech = WWW::Mechanize->new(); 08: 09: $mech->cookie_jar(HTTP::Cookies->new()); 10: $mech->get( "https://mySite.de/admin" ); 11: 12: #Get ADMIN-ID 13: $mech->content() =~ /name=\"ADMIN\" value=\"([^\"]+)/g; 14: $hiddenField = $1; 15: 16: #Fill form 17: $mech->submit_form( 18: form_name => "action", 19: fields => { 20: ADMIN => $hiddenField, 21: username => $username, 22: password => $password}, 23: button => 'login'); 24: 25: #Print site 26: print $mech->content(); 27:

My first though was 'Maybe I'm getting redirected!?" I checked that and it's not the case.
Here the results from'LWP::Debug qw(+)':
LWP::UserAgent::new: () LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking <<URL>> for cookies LWP::UserAgent::send_request: GET https://mySite/admin LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 242 bytes LWP::UserAgent::request: Simple response: Moved Permanently LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking <<URL>> for cookies LWP::UserAgent::send_request: GET https://mySite/admin LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 4096 bytes LWP::Protocol::collect: read 965 bytes HTTP::Cookies::extract_cookies: Set cookie ADMIN => 829052f0173388362a +649d8fe980081b LWP::UserAgent::request: Simple response: OK LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking <<URL>> for cookies HTTP::Cookies::add_cookie_header: - checking cookie path=/ HTTP::Cookies::add_cookie_header: - checking cookie ADMIN=829052f0173 +388362a649d8fe980081b HTTP::Cookies::add_cookie_header: it's a match HTTP::Cookies::add_cookie_header: Checking <<URL>> for cookies LWP::UserAgent::send_request: POST https://mySite/admin/index.php?acti +on=login LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 238 bytes LWP::Protocol::collect: read 540 bytes LWP::Protocol::collect: read 2348 bytes LWP::Protocol::collect: read 219 bytes LWP::Protocol::collect: read 419 bytes LWP::Protocol::collect: read 160 bytes LWP::Protocol::collect: read 1122 bytes LWP::UserAgent::request: Simple response: OK

In reply to Secure login (https + Certificate) using Perl by Finch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (9)
    As of 2014-09-18 18:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (120 votes), past polls