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

Hi there. I'm creating a little robot program to get some info from game site. And I faced a problem that my robot wouldn't login... The form they use for logging in looks like this
<form name="Form1" method="post" action="default.aspx" id="Form1"> <input type="hidden" name="__VIEWSTATE" value="dDwtM" /> <input name="tbLogin" type="text" size="14" id="tbLogin" /> <input name="tbPassword" type="password" size="14" id="tbPassword" /> <input type="image" name="btLogin" id="btLogin" src="/vr/images/bt_ent +er.jpg" alt="" style="border-width:0px;border-style:None;" /> </form>
And as far as i figured out problem is because they don't use submit button but <input type=image> and as for my robot text it goes like this
my $response = $browser->post( $url, [ 'tbLogin' => 'value', 'tbPassword' => 'value', '__VIEWSTATE' => 'value', ] );
And all the time my robot get reply that it performed illegal login operation, and wouldn't go through loging process. I think that it' because i don't specify btLogin in post method of browser, but there is no value to put with it... Their site is in ASP.net.
Any ideas?

Replies are listed 'Best First'.
Re: LWP browser problem
by inman (Curate) on Nov 03, 2005 at 14:57 UTC
    The first thing to try is to analyse the login procedure using a tool like Mozilla (or Firefox) with the 'Live HTTP Headers' plugin loaded. This will help you to track the exchange between a browser and the site. You can then modify your script to work in the same way.

    You should also look at WWW::Mechanize as it is specially designed for this sort of thing.

    Other points to consider:

    1. Does the site require cookies? You will need to add a cookie jar if it does.
    2. Does the site object to non-browser agents? You will need to change the agent name if it does.
    3. Does the POSTed data cause the browser to redirect? This is something that you will need to prompt LWP to do.

    Can you also post the code that you tried so that we can see what is going on!

Re: LWP browser problem
by slayven (Pilgrim) on Nov 03, 2005 at 20:57 UTC
    AFAIR the submit-value of an input type="image" append the coordinates of the mouse-click on the given image (or maybe browser). However, the script that captures the form gets something like
      btLogin.X => $numeric,
      btLogin.Y => $numeric,
    
    To be sure just copy the HTML-Code from the site, change the action location into a location of a small CGI script that captures all submitted values. It may be as small as the following:
    use CGI; use Data::Dumper; my $q = new CGI; my %vars = $q->Vars(); print "Content-Type: text/plain\n\n"; print Dumper(\%vars);
    After submitting your copied form you'll see exactly the same parameters the ASP-site gets from the original site.
    -- slayven
            trust in bash
            but tie your camel