How do I 'POST' to a page and populate the Form Data?

I inspected one of my own pages thinking 'how does the username and password get passed to the server' and when I ran fiddler I have the following:

POST http://vls.pete/Login.aspx HTTP/1.1 Host: vls.pete User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-gb,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Referer: http://vls.pete/Login.aspx Cookie: ASP.NET_SessionId=yc2zsqveono2vm000d4liexp Content-Type: multipart/form-data; boundary=---------------------------21724139663430 Content-Length: 2054 -----------------------------21724139663430 Content-Disposition: form-data; name="__VIEWSTATE" /wEPDwUKLTQ2NzI2Mzk5Mw9kFgJmD2QWAgIDD2QWCgIBDw8WAh4HVmlzaWJsZWhkFgICAQ9kFgICBw8QD2QWAh4Hb25jbGljawWLASByZXR1cm4gQ29uZmlybUFjdGlvbignQXJlIHlvdSBzdXJlIHlvdSB3YW50IHRvIGRvIHRoaXM/IENsaWNrICJDYW5jZWwiIGlmIHlvdSBhcmUgb24gYSBwdWJsaWMgY29tcHV0ZXIuJyxjdGwwMF91Y0xvZ2luUGFuZWxfY2JSZW1lbWJlck1lKTtkZGQCAw8PFgIeCEltYWdlVXJsBTh+L0ltYWdlcy9weF90b3AuZ2lmPzBhMDAyM2U5LTZmNDktNGE3OS05YjVmLWVkNWNhYmUzYTEzM2RkAgUPZBYCZg8WAh8AaBYGAgEPFgIfAGhkAgIPFgIeBGhyZWYFKmh0dHA6Ly91cGxvYWQucGV0ZS52aWRlb2xpYnJhcnlzZXJ2ZXIuY29tL2QCAw8PZBYCHgpvbmtleXByZXNzBTNyZXR1cm4gc3VibWl0QnlUYXJnZXQoZXZlbnQsY3RsMDBfTWVudTFfYnRuU2VhcmNoKTtkAgcPZBYCAgEPZBYCAgEPDxYCHwBnZBYCAgcPEA9kFgIfAQWXASByZXR1cm4gQ29uZmlybUFjdGlvbignQXJlIHlvdSBzdXJlIHlvdSB3YW50IHRvIGRvIHRoaXM/IENsaWNrICJDYW5jZWwiIGlmIHlvdSBhcmUgb24gYSBwdWJsaWMgY29tcHV0ZXIuJyxjdGwwMF9tYWluQ29udGVudF91Y0xvZ2luUGFuZWxfY2JSZW1lbWJlck1lKTtkZGQCCw8PFgIfAgU7fi9JbWFnZXMvcHhfYm90dG9tLmdpZj84NDI1NDcwMS05YzM0LTRiNzktOTNjYS1hYzhkNDkzMTNhZmVkZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAQUrY3RsMDAkbWFpbkNvbnRlbnQkdWNMb2dpblBhbmVsJGNiUmVtZW1iZXJNZRyd69fCCRneUrdS6l+kP20eGdW9KljXv9Gbp2hVtCd1 -----------------------------21724139663430 Content-Disposition: form-data; name="__EVENTTARGET" -----------------------------21724139663430 Content-Disposition: form-data; name="__EVENTARGUMENT" -----------------------------21724139663430 Content-Disposition: form-data; name="__EVENTVALIDATION" /wEWBQKpta7uDALlkKHqBQK/x+yDBgL2koVLAvSJ7pkMkU0QjNaNcJgsKX6cXUSVq18/Kqfcx+yfjUfB2mLQt64= -----------------------------21724139663430 Content-Disposition: form-data; name="ctl00$mainContent$ucLoginPanel$tbUserName" admin -----------------------------21724139663430 Content-Disposition: form-data; name="ctl00$mainContent$ucLoginPanel$tbPassword" password -----------------------------21724139663430 Content-Disposition: form-data; name="ctl00$mainContent$ucLoginPanel$lbLogin" Login -----------------------------21724139663430--

What im wondering is how I would call a page programatically from javascript and implement single login for a user, what would happen to the cookies etc?.

Any advice on how to log in a user via script or any other method much appreciated.

-------------Problems Reply------------

If you use a JavaScript XMLHttpRequest (http://www.w3schools.com/xml/xml_http.asp), then the browser's cookies will be sent to the server with the request. Further, any cookies the server returns in its response will be added to the browser session. So if you log your user on with this mechanism then cookie-based authentication should work.

Note that you will only be able to read these response cookies from JavaScript using document.cookies after the next page load.

Category:c# Views:0 Time:2011-02-17

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.221 (s). 11 q(s)