The stupid question is the question not asked | |
PerlMonks |
Multiple Step Login in Perlby sylph001 (Sexton) |
on May 20, 2014 at 16:18 UTC ( [id://1086815]=perlquestion: print w/replies, xml ) | Need Help?? |
sylph001 has asked for the wisdom of the Perl Monks concerning the following question:
Respective Monks, I'm trying to login to a vendor web site in order to fetch some data, but their asp+ajax+jquery web site always prevent me from getting in, either via LWP or curl. Here's how the web site is like: 1. The login page (www.xxxx.gov/pages/profile.aspx) expects me to enter my email address (which was used during registering). After hit 'submit' button, I should be brought to the 'login question verify' page. 2. On the verify page, I was expected to fill in an answer to the account verify question. Then by hitting 'verify' button, I should get login and see the my account profile, while the cookie is also got. Using firebug, I noticed every time I hit 'submit' or 'verify' button, it sent a 'GetUpdatedFormDigest' request in SOAP body, and then did the normal POST with the '__REQUESTDIGEST=<DigestValueReturned>' in content. So, I used LWP to imitate the SOAP request and got a response with a Digest Value which seems reasonable. Then I did the normal $ua->post() with this Digest Value and other form parameters I got from the very first login page. I thought I had posted all the form parameters I could see in firebug (and HttpWatch); but every time, I can only get a respond with exactly same html page as the very first login page - which, was requesting the login email address again. Here I paste the request headers that I caught from a successful login in the browser, with firebug: 1. Header of the SOAP request from the browser: (Request-Line) POST http://www.xxxxxxxxx.gov/_vti_bin/sites.asmx HTTP/1.1 Accept */* Accept-Encoding gzip, deflate Accept-Language en-US,en;q=0.8 Content-Length 332 Content-Type text/xml Host www.xxxxxxxxx.gov Origin http://www.xxxxxxxxx.gov Pragma no-cache Proxy-Connection Keep-Alive Referer http://www.xxxxxxxxx.gov/pages/profile.aspx SOAPAction http://schemas.microsoft.com/sharepoint/soap/GetUpdatedFormDigest User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; chromeframe/27.0.1453.94) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36 What I wrote in perl to produce this SOAP request: 133 $res = $ua->request( 134 POST "http://www.xxxxxxxxx.gov/_vti_bin/sites.asmx", 135 Content_Type => 'text/xml', 136 Referer => 'http://www.xxxxxxxxx.gov/pages/profile.aspx', 137 X-Requested-With => 'XMLHttpRequest', 138 Proxy-Connection => 'Keep-Alive', 139 User-Agent => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0', 140 Content => ${SOAP_BODY} 141 ); 2. Header of the normal POST request from browser, which should be responded with the next html page: (Request-Line) POST http://www.xxxxxxxxx.gov/pages/profile.aspx HTTP/1.1 Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language en-US,en;q=0.8 Content-Length 4570 Content-Type application/x-www-form-urlencoded Host www.xxxxxxxxx.gov Origin http://www.xxxxxxxxx.gov Pragma no-cache Proxy-Connection Keep-Alive Referer http://www.xxxxxxxxx.gov/pages/profile.aspx User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; chromeframe/27.0.1453.94) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36 Again, what I wrote in my program to imitate this header: 148 my $header = HTTP::Headers->new( 149 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 150 'Accept-Encoding'=>'gzip, deflate', 151 'Proxy-Connection'=> 'Keep-Alive', 152 'Host' => 'www.xxxxxxxxx.gov', 153 'Referer' => 'http://www.xxxxxxxxx.gov/pages/profile.aspx', 154 'User-Agent'=> 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0', 155 'Content-Type'=>'application/x-www-form-urlencoded', 156 'Origin' => 'http://www.xxxxxxxxx.gov', 157 'Accept-Language'=>'en-US,en;q=0.8', 158 'Pragma' => 'no-cache' 159 160 ); 161 $ua->default_headers($header); Dear Monks, could you let me know what I have missed in my praying that caused the vendor website shutting me out? Thank you
Back to
Seekers of Perl Wisdom
|
|