首 页文章中心下载中心繁體中文
设为首页
加入收藏
联系我们
您当前的位置:开源盛世-源代码下载网 -> 文章中心 -> 其他编程 -> VC# 技术 -> 文章内容 退出登录 用户管理
栏目导航
· VC# 技术 · Delphi技术
· Java技术 · 通用算法
· 编程相关
热门文章
· Tab Control控件使用...
· 学生档案管理系统
· [图文] 排列组合公式
· UTF-8与GB2312之间的...
· DirectShow下载安装...
· Virtual PC 在PAE模...
· Windows2000终端服务...
· MapInfo上的GIS系统...
· Mapbasic参考手册索...
· MapX应用开发中文讲...
相关文章
C#(WINFORM)实现模拟POST发送请求登录网站
作者:不详  来源:vscodes.com整理  发布时间:2007-8-5 14:29:24  发布人:Polaris

减小字体 增大字体

最近接了个小项目,用到一个技术需要模拟POST向Web服务器发送请求来进行登录,下面写一下主要代码。

              string strId = "admin";//用户名

              string strPassword = "xxxxx";//密码
              //string strsubmit = "YES";
              ASCIIEncoding encoding = new ASCIIEncoding();
              string postData = "username=" + strId;
              postData += ("&password=" + strPassword);
              //postData += ("&Accept=" + strsubmit);
              byte[] data = encoding.GetBytes(postData);
              // Prepare web request...
              HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("
http://www.csharpcn.com/login.aspx");
              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.UTF8);
              string content = reader.ReadToEnd();
              //Response.Write(content);
              textBox1.Text = content;

以上代码放到一个方法里就可以获取登录CSHARPCN后的第一个页面了。

End of《C#(WINFORM)实现模拟POST发送请求登录网站》

[] [返回上一页] [打 印] [收 藏]
 
∷相关“C#(WINFORM)实现模拟POST发送请求登录网站”文章评论∷
(评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 网站目录 鄂ICP备06007162
开源盛世 版权所有Copyright © 2003-2005 VSCodes.Com. All Rights Reserved.