POSTing username and password to web server with cookie enabled

P

Paul

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 => '(e-mail address removed)',
_txtPassword => '4testpurpose',
__EVENTTARGET=>'subBtn',
__EVENTARGUMENT=>'',
__VIEWSTATE=>$sbviewstate,
],
REFERER => $LOGIN);

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

/////////////////////////////////////////////////////////////////////////
 
B

Brian Wakem

Paul said:
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.
 
P

Paul

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 => '(e-mail address removed)',
_txtPassword => '4testpurpose',
__EVENTTARGET=>'subBtn',
__EVENTARGUMENT=>'',
__VIEWSTATE=>$sbviewstate,
],
REFERER => $LOGIN);

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top