如何“发布”到页面并填充表单数据?

时间:2011-02-17 12:34:05

标签: c# javascript asp.net html

我检查了一个我自己的页面,想'用户名和密码如何传递到服务器',当我运行fiddler时,我有以下内容:

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--

我想知道如何以编程方式从javascript调用页面并为用户实现单点登录,cookie会发生什么??

有关如何通过脚本或任何其他方法登录用户的任何建议。

1 个答案:

答案 0 :(得分:1)

如果您使用JavaScript XMLHttpRequest(http://www.w3schools.com/xml/xml_http.asp),则浏览器的cookie将随请求一起发送到服务器。此外,服务器在其响应中返回的任何cookie都将添加到浏览器会话中。因此,如果您使用此机制登录用户,则基于cookie的身份验证应该有效。

请注意,您只能在下一页加载后使用document.cookies从JavaScript中读取这些响应Cookie。