request = (HttpWebRequest)WebRequest.Create(url);
if (Const.session != null)
{
request.Headers.Add("Cookie", Const.session);
}
request.Timeout = 30000; //设定超时值
request.ContentType = "application/octet-stream";
request.Method = "POST";
request.ContentLength = outData.Length;
stream = request.GetRequestStream();
stream.Write(outData, 0, outData.Length);
stream.Flush();
stream.Close();
Const.uiWaitMessage = "请求发送完毕,开始接收数据";
Thread.Sleep(500);
//发送完毕
//接收数据
response = (HttpWebResponse)request.GetResponse();
if (Const.session == null)
{// 注销后要清除Common.session
String cookie = response.GetResponseHeader("Set-Cookie");
if (cookie != null)
{
int n = cookie.IndexOf(';');
if (n > -1) Const.session = cookie.Substring(0, n);
}
}
使用
if (Const.session == null)
{// 注销后要清除Common.session
String cookie = response.GetResponseHeader("Set-Cookie");
if (cookie != null)
{
int n = cookie.IndexOf(';');
if (n > -1) Const.session = cookie.Substring(0, n);
}
}
可以获得并保存网站分配的Session信息
这样每次访问指定url的时候就可以先用
if (Const.session != null)
{
request.Headers.Add("Cookie", Const.session);
}
来添加Cookie,将已获得Session信息发送到网站。
---------------------------------------------------------
专注移动开发
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2008-10-04 10:41
TiGERTiAN 阅读(1649)
评论(1) 编辑 收藏 所属分类:
DotNet 、
Windows Mobile