会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
㊣点滴伊飏
博客园
首页
新随笔
订阅
管理
提交Html请求并保存身份信息
//
创建请求
HttpWebRequest mRequest
=
WebRequest.Create("
http://www.a.com
/Login.aspx
"
)
as
HttpWebRequest;
mRequest.Method
=
"
POST
"
;
mRequest.ContentType
=
"
application/x-www-form-urlencoded
"
;
mRequest.AllowAutoRedirect
=
false
;
mRequest.CookieContainer
=
new
CookieContainer();
string
strPostData
=
"username=aaa&userpwd=bbb";
byte
[] buffer
=
System.Text.Encoding.UTF8.GetBytes(strPostData);
mRequest.ContentLength
=
buffer.Length;
//
发送数据
Stream stream
=
mRequest.GetRequestStream();
stream.Write(buffer,
0
, buffer.Length);
stream.Close();
//
得到响应
wr
=
(HttpWebResponse)mRequest.GetResponse();
CookieCollection cc
=
mRequest.CookieContainer.GetCookies(mRequest.Address);
//
读取响应内容
sr
=
new
StreamReader(wr.GetResponseStream(), System.Text.Encoding.GetEncoding(
"
gb2312
"
));
//
显示在浏览器中
browser.Navigate(
"
about:blank
"
);
browser.DocumentText
=
sr.ReadToEnd();
//
关闭
sr.Close();
wr.Close();
再次提交时,将cc加入到请求对象的CookieContainer中。
posted @
2006-03-17 20:17
伊飏
阅读(
595
) 评论(
0
)
收藏
举报
刷新页面
返回顶部