生成的html内容

<body>
    <form method="post" action="./Login.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTE3NTYyOTE3Ng9kFgICAQ9kFgICBQ8PZBYCHgdvbmNsaWNrBS50aGlzLmRpc2FibGVkPXRydWU7X19kb1Bvc3RCYWNrKCdidG5Mb2dpbicsJycpZGTYVIQduJiktQAsjmET0WpCKVEwoSyPSdqBY5R5rDqlKA==" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<div class="aspNetHidden">

    <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="82312306" />
    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAASgOrQ71iMnYy6bc/2yqhwyR1LBKX1P1xh290RQyTesRe73C5Hghb+Z/bZTMreJjC6inihG6d/Xh3PZm3b5AoMQw8nbR9PLyUvJjDo4AdVamTiJMoO8PpF19MUnfVREfjA=" />
</div>
        <div class="top_div" style="text-align:center;"></div>
        <div style="background: rgb(255, 255, 255); margin: -100px auto auto; border: 1px solid rgb(231, 231, 231); border-image: none; width: 400px; height: 230px; text-align: center;">
            <div style="width: 165px; height: 96px; position: absolute;">
                <div class="tou"></div>
                <div class="initial_left_hand" id="left_hand"></div>
                <div class="initial_right_hand" id="right_hand"></div>
            </div>
            <P style="padding: 30px 0px 10px; position: relative;">
                <span class="u_logo"></span>         
                <input name="UserName" type="text" id="UserName" class="ipt" placeholder="请输入用户名" /> 
            </P>
            <P style="position: relative;">
                <span class="p_logo"></span>         
                <input name="UserPass" type="password" id="UserPass" class="ipt" placeholder="请输入密码" />   
            </P>
            <div style="height: 50px; line-height: 50px; margin-top: 30px; border-top-color: rgb(231, 231, 231); border-top-width: 0px; border-top-style: solid;">
                <P style="margin: 0px 35px 20px 45px;">
                    <input type="submit" name="btnLogin" value="登录" onclick="this.disabled=true;__doPostBack(&#39;btnLogin&#39;,&#39;&#39;);" id="btnLogin" style="height:28px;width:60px;" />
                </P>
            </div>
            <div style="height: 20px; line-height: 20px; margin-top: 0px; border-top-color: rgb(231, 231, 231); border-top-width: 0px; border-top-style: solid;">
                 <span id="lblMsg" style="color:Red;background-color:Transparent;"></span>
            </div>
        </div>
        <div style="text-align:center;"></div>
    </form>
</body>
</html>

 

上面二行加粗的是必带的viewstatus属性

下面是模拟请求的代码

string strViewState = System.Web.HttpUtility.UrlEncode("/wEPDwUKMTE3NTYyOTE3Ng9kFgICAQ9kFgICBQ8PZBYCHgdvbmNsaWNrBS50aGlzLmRpc2FibGVkPXRydWU7X19kb1Bvc3RCYWNrKCdidG5Mb2dpbicsJycpZGTYVIQduJiktQAsjmET0WpCKVEwoSyPSdqBY5R5rDqlKA==");
            string strEventValidation = System.Web.HttpUtility.UrlEncode("/wEdAASgOrQ71iMnYy6bc/2yqhwyR1LBKX1P1xh290RQyTesRe73C5Hghb+Z/bZTMreJjC6inihG6d/Xh3PZm3b5AoMQw8nbR9PLyUvJjDo4AdVamTiJMoO8PpF19MUnfVREfjA=");

            StringBuilder url = new StringBuilder();
            url.Append("UserPass=123456");
            url.Append("&UserName=whtydn");
            url.Append("&UserName=whtydn");
            url.Append("&__VIEWSTATE="+ strViewState);
            url.Append("&__EVENTVALIDATION=" + strEventValidation);
            url.Append("&btnLogin=登录");

            byte[] data = System.Text.Encoding.ASCII.GetBytes(url.ToString());

            Uri uri = new Uri("http://www.etaor.com/Admin/Login.aspx");
            System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
            request.Method = "post";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(data, 0, data.Length);
            requestStream.Close();

            System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader readStream = new StreamReader(responseStream, System.Text.Encoding.UTF8);
            string retext = readStream.ReadToEnd().ToString();
            readStream.Close();

            Console.WriteLine("Result: " + retext);
posted on 2016-07-11 18:22  风浪  阅读(1065)  评论(0编辑  收藏  举报