I've been trying to login to an https website without much luck. I started by using Firefox's HTTPfox plugin to capture all of the POST data that is sent when I login via the browser:

__EVENTTARGET __EVENTARGUMENT __VIEWSTATE /wE<lots of random text>= __EVENTVALIDATION /wEWBwKC8PjxBAKA67T+BwKO6KL2BAKLq4PJCgL29+SDDQLV0uz +nBgLC1O+bAovDyVQCQToaE9MTGjwpHkcZ9bRh cid_654$tbSearch jsMenu cid_40$txtUsername <username> cid_40$txtPassword <password> cid_40$btnLogin Login

I then created my perl code as follows:

#!/usr/bin/perl -w use strict; use WWW::Mechanize; my $post_response = ""; my $m = WWW::Mechanize->new(); $m->agent_alias('Linux Mozilla'); $m->add_handler("request_send", sub { shift(@_)->dump(); return }); my $url = "http://alumni.nd.edu/s/1210/start.aspx?sid=1210&gid=1&pgid= +3&cid=40"; $m->get($url); $post_response = $m->submit_form( form_number => 1, button => 'cid_40$btnLogin', fields => { 'cid_40$txtUsername' => '<username>', 'cid_40$txtPassword' => '<password>', '__EVENTTARGET' => '', '__EVENTARGUMENT' => '', 'cid_654$tbSearch' => '', 'jsMenu' => '', 'cid_40$btnLogin' => 'Login' } ); printf("POST RESPONSE STATUS LINE: %s\n", $post_response->status_line) +; printf("POST RESPONSE HEADER TITLE: %s\n", $post_response->header('tit +le'));

It's not logging me into the website. I can tell because the call to $post_response->header('title') at the bottom returns nothing, yet I know the page you go to after logging in has a title field. Here's an excerpt from my program's output following the POST command:

POST https://securelb.imodules.com/s/1210/index.aspx?sid=1210&gid=1&pg +id=3&cid=40 Accept-Encoding: gzip Referer: http://alumni.nd.edu/s/1210/start.aspx?sid=1210&gid=1&pgid=3& +cid=40 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/2003 +0624 Content-Length: 9420 Content-Type: application/x-www-form-urlencoded __VIEWSTATE=%2FwEPDwUKMjAwMzk3MTQyNA9kFgICAw8WAh4FY2xhc3MFDklNT0QzIGlu +dGVyaW9yFgICAQ9kFhACAg8WAh4HVmlzaWJsZWcWBGYPDxYCHwFoZGQCAQ8PFgIfAWhkF +gQCAg9kFgICAQ9kFgICAQ9kFgQCAQ9kFgJmDxQrAAIUKwACZBAWA2YCAQICFgMUKwACDx +YGHgRUZXh0BQlEYXNoYm9hcmQeC05hdmlnYXRlVXJsBWdodHRwczovL2FkbWlubGIuaW1 +vZHVsZXMuY29tL2FkbWluL2luZGV4LmFzcHg%2Fc2lkPTEyMTAmZ2lkPTEmcGdpZD0yOT +AmZG9jdHlwZT14aHRtbCZjaWQ9JmJwaWQ9MjkwJm11aWQ9HgVWYWx1ZQUJY2xpY2thYmx +lFgIeBXN0eWxlBQ9jdXJzb3I6cG9pbnRlcjtkFCsAAg8WBh8CBQdDb250ZW50HwMFL2h0 +dHA6Ly9teW5vdHJlZGFtZS5uZC5l... (+ 8908 more bytes not shown) GET http://mynotredame.nd.edu/?sid=1210&gid=1&pgid=61&muid=AUTH_b97c52 +30-1f64-4005-abf8-3fd6c28b56a9 Accept-Encoding: gzip Referer: http://alumni.nd.edu/s/1210/start.aspx?sid=1210&gid=1&pgid=3& +cid=40 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/2003 +0624 (no content) GET http://mynotredame.nd.edu/s/1210/start.aspx?sid=1210&gid=1&pgid=61 +&muid=AUTH_b97c5230-1f64-4005-abf8-3fd6c28b56a9 Accept-Encoding: gzip Referer: http://alumni.nd.edu/s/1210/start.aspx?sid=1210&gid=1&pgid=3& +cid=40 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/2003 +0624 (no content) GET http://mynotredame.nd.edu/s/1210/start.aspx?sid=1210&gid=1&pgid=61 Accept-Encoding: gzip Referer: http://alumni.nd.edu/s/1210/start.aspx?sid=1210&gid=1&pgid=3& +cid=40 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/2003 +0624 Cookie: AL_LastUpdated=3/15/2013 9:54:25 AM; WOL_LastUpdated=3/15/2013 + 9:54:25 AM; .ASPXIMODAUTH=D75599B33280C1BD9EA223B07B0AC3014377703CD7 +5F81AC75227DFFDB3745D1F0479573FFFD174B4A989B5A8492CAB1569C079B9E2F862 +AD1B9FCF61A5289FE15E1FE13169DFE6BCC55B82C396CF5360EDA625385BE95D46EF6 +CB853B08C222562E2C4D96CED1A63043E6A0A416B595C8505102DC48C3B5F21C039FA +351EE0F88FD439C8AC41D58149CE174996C58CA50B2F4B5064EDC59DBAE7781EABC8E +17D015B37862E22ABC7329171B6B2768FAB55DDD3657E33E3BA168BCE852D9056A160 +75F60 Cookie2: $Version="1" (no content) POST RESPONSE STATUS LINE: 200 OK Missing argument in printf at www_debug.pl line 38. POST RESPONSE HEADER TITLE:

Does anyone have any idea why it's not letting me log in? I tried including the __VIEWSTATE and __EVENTVALIDATION fields in my submission, but that didn't help anything.


In reply to trouble logging into website using WWW::Mechanize by Special_K

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.