首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

小高分乞援,关于HttpWebResponse 返回

2011-12-20 
小高分求助,关于HttpWebResponse 返回用C#做一个模拟登陆页面,不能返会响应后的页面C# code String loginU

小高分求助,关于HttpWebResponse 返回
用C#做一个模拟登陆页面,不能返会响应后的页面

C# code
 String loginUrl = "http://localhost/yh/admin/login.asp"; CookieContainer session = new CookieContainer();  public void getLoginPage()        {            string strUsername = tb_username.Text.Trim();            string strPassword = tb_password.Text.Trim();            ASCIIEncoding encoding = new ASCIIEncoding();            string postData = "username=" + strUsername;            postData += ("&password=" + strPassword);            //postData = "username=steve&password=123456a%mofei=7049&submit=%C8%B7+%B6%A8";            byte[] data = encoding.GetBytes(postData);            // Prepare web request...               HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(loginUrl);                             myRequest.CookieContainer = session;            myRequest.Method = "POST";            myRequest.ContentType = "application/x-www-form-urlencoded";            myRequest.ContentLength = data.Length;            Stream newStream = myRequest.GetRequestStream();                        // Send the data.               newStream.Write(data, 0, data.Length);                   newStream.Close();            // Get response               HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);            string content = reader.ReadToEnd();            richTextBox1.Text = richTextBox1.Text + content;        }


login.asp
HTML code
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>

<form name="form1" method="post" action="login_chk.asp">
<table>
    <tr>
      <td height="30"  colspan="2" align="center" bgcolor="#E8E8E8" class="td_2"> <b>管理登陆 </b> </td>
    </tr>
    <tr>
      <td width="80" align="center" class="td_2">用户名: </td>
      <td width="220" class="td_2"> <input type="text" name="username" class="input1" size="19"> </td>
    </tr>
    <tr>
      <td align="center" class="td_2">密&nbsp;&nbsp;码: </td>
      <td class="td_2"> <input type="password" name="password" class="input1" size="19"> </td>
    </tr> 
    <tr>
      <td height="30" colspan="2" align="center" valign="middle" class="td_2"> <input style="color: #FFFFFF; background-color: #FF1171; border: 1px solid #000000" type="submit" value="确 定" name="Submit">
&nbsp;&nbsp;&nbsp;
      <input style="color: #FFFFFF; background-color: #FF1171; border: 1px solid #000000" type="reset" value="取 消" name="Submit2"> </td>
    </tr>
</table>
  </form>



<body>
</body>
</html>




login_chk.asp
HTML code
<%if Request("username") ="1" and Request("password") = "1" then        Response.Write("用户登陆成功")else    Response.Write ("请输入正确的用户名和密码")end if%>


[解决办法]
mark UP一下
[解决办法]

UP
[解决办法]
up

热点排行