POSTing username and password to web server with cookie enabled

Discussion in 'Perl Misc' started by Paul, Aug 20, 2005.

  1. Paul

    Paul Guest

    hi, greetings,

    I am trying to write a script to login www.dell.com/myaccount, so I can
    track my order automatically. Following is the first step to login
    https://membership.dell.com/DellLogin/GA/login.aspx, where the user
    should input username and password. there is no compile error in my
    scipit. My question is that I can not login the website using this
    script. I printed the content, it showed that the server always told me
    that "An Error has Occurred
    An error has occurred while trying to validate your e-mail and
    password. Please try again later. ". But when I tried to login with a
    wrong password, the server will tell me "Please correct the following
    problem(s) before continuing.
    The E-mail address and password combination you entered does not match
    any accounts on record. Please try again. To create an account, click
    here. Note that If you submit incorrect password information 6 times,
    your account will be locked. "

    So it seems that the script somepart works. But I dont know how to fix
    it so that I can login the website.

    The passord and email adress in the script are the ture username and
    password, you can use them to login the website using IE.

    Any help are highly appreciated. Thank you so much for you guys.

    ////////////////////////////////////////////////////////

    use strict;
    use LWP;
    use HTTP::Request::Common;
    use HTTP::Cookies;

    my $LOGIN='https://membership.dell.com/DellLogin/GA/login.aspx';
    my $sbviewstate='dDwtMjA2Mjg0NzcwMjs7Pg==';
    my $ua = LWP::UserAgent->new;
    $ua->cookie_jar(new HTTP::Cookies);
    my $newagent = 'Mozilla/4.51 [en]';
    $ua->agent($newagent);

    my $response = $ua->request(GET($LOGIN));
    my $request = POST ($LOGIN,
    [ _txtUserName => '',
    _txtPassword => '4testpurpose',
    __EVENTTARGET=>'subBtn',
    __EVENTARGUMENT=>'',
    __VIEWSTATE=>$sbviewstate,
    ],
    REFERER => $LOGIN);

    $response = $ua->request($request);
    print $response->content;

    /////////////////////////////////////////////////////////////////////////
     
    Paul, Aug 20, 2005
    #1
    1. Advertising

  2. Paul

    Brian Wakem Guest

    Paul wrote:

    > my $sbviewstate='dDwtMjA2Mjg0NzcwMjs7Pg==';



    I think you'll find the viewstate will change everytime. You'll need to
    request the login page, extract the viewstate and submit it.

    Failing that you need to see what is being sent back and forth. See the
    'Understanding Mechanize' thread started yesterday.


    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Aug 20, 2005
    #2
    1. Advertising

  3. Paul

    Paul Guest

    actually the "__VIEWSTATE" does not change each time. my new code:

    use strict;
    use LWP;
    use HTTP::Request::Common;
    use HTTP::Cookies;

    my $LOGIN='https://membership.dell.com/DellLogin/GA/login.aspx';
    my $sbviewstate;
    my $ua = LWP::UserAgent->new;
    $ua->cookie_jar(new HTTP::Cookies);
    my $newagent = 'Mozilla/4.51 [en]';
    $ua->agent($newagent);
    my $response;
    my $ident;
    my $pos1;
    my $pos2;

    #############Get the _viewstate##################
    $response = $ua->get($LOGIN);
    print "Error at $LOGIN\n ", $response->status_line, "\n Aborting"
    unless $response->is_success;

    #print $response->content;
    $ident = 'name="__VIEWSTATE" value="';
    $pos1 = index($response->content, $ident) + length $ident;
    $pos2 = index $response->content, '"', $pos1;
    $sbviewstate=substr($response->content, $pos1, $pos2-$pos1);
    #############Get _viewstate ends###################

    #print $sbviewstate;

    my $response = $ua->request(GET($LOGIN));
    my $request = POST ($LOGIN,
    [ _txtUserName => '',
    _txtPassword => '4testpurpose',
    __EVENTTARGET=>'subBtn',
    __EVENTARGUMENT=>'',
    __VIEWSTATE=>$sbviewstate,
    ],
    REFERER => $LOGIN);

    $response = $ua->request($request);
    print $response->content;




    Brian Wakem wrote:
    > Paul wrote:
    >
    > > my $sbviewstate='dDwtMjA2Mjg0NzcwMjs7Pg==';

    >
    >
    > I think you'll find the viewstate will change everytime. You'll need to
    > request the login page, extract the viewstate and submit it.
    >
    > Failing that you need to see what is being sent back and forth. See the
    > 'Understanding Mechanize' thread started yesterday.
    >
    >
    > --
    > Brian Wakem
    > Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Paul, Aug 20, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabor
    Replies:
    3
    Views:
    629
    Jacob Yang [MSFT]
    Aug 26, 2003
  2. AAaron123
    Replies:
    2
    Views:
    2,202
    AAaron123
    Jan 16, 2009
  3. AAaron123
    Replies:
    1
    Views:
    1,357
    Oriane
    Jan 16, 2009
  4. Shailesh Patel
    Replies:
    0
    Views:
    466
    Shailesh Patel
    Nov 8, 2006
  5. Replies:
    0
    Views:
    115
Loading...

Share This Page