关于Cookie的问题,整和系统所用(System.Net.Cookie和HttpCookie)

wobone 2009-04-03 10:14:16
需求描述:
我是写的一个用程序发出请求,得到响应,登陆后可以得到cookie,通过得到的cookie(session也是利用cookie嘛),可以用程序向下面这样访问登陆后的页面,而现在我要的效果是:当这个aspx页面(这段程序暂时写在aspx.cs里面),发送到客户端浏览器
时,此浏览器也可以访问登陆后操作, 我的思路是,当aspx页面发送到浏览器时,将用程序得到的System.Net.Cookie 写到客户端去,让浏览器再次访问此地址时自动发送cookie 就可以访问登陆后页面了,下面是代码:

string url4 = "http://mis.lohoo.com/mis/reservation/newrev3/addnew1.asp?come_from_hba=hba";

string postData4 = "hotel_name={0}&come_from_hba=hba&card_no=613613285&password=lohoo&arrive_date=2009-4-2&leave_date=2009-4-3&mis_map=yes&isreserve=0&query=query";
postData4 = postData4.Replace("{0}", "北京好意舍酒店");
byte[] byteArray4 = System.Text.Encoding.GetEncoding("GB2312").GetBytes(postData4);
Uri u4 = new Uri(url4);
HttpWebRequest request4 = (HttpWebRequest)WebRequest.Create(u4);
request4.CookieContainer = cc;
request4.Method = "POST";
request4.ContentType = "application/x-www-form-urlencoded";
request4.ContentLength = byteArray4.Length;
request4.AllowAutoRedirect = true;
Stream newStream4 = request4.GetRequestStream();
newStream4.Write(byteArray4, 0, byteArray4.Length); //写入参数
newStream4.Close();
HttpWebResponse webresponse4 = (HttpWebResponse)request4.GetResponse();

foreach (Cookie cookie in cc.GetCookies(request4.RequestUri))
{
HttpCookie cookie1 = new HttpCookie(cookie.Name, cookie.Value);
Response.Cookies.Add(cookie1);
}
StreamReader sr5 = new StreamReader(webresponse4.GetResponseStream(), Encoding.Default);
string htmlCode5 = sr5.ReadToEnd();

string aa = diggerUtils.cutHtml(htmlCode5, "<table width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">","</table>");
Literal1.Text = "<table>"+aa+"</table>";



涉及到两个方面:一是如何把此程序的到的cookie写到客户端去,上面办法不行.二是 System.Net.Cookie 转 HttpCookie
...全文
134 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wobone 2009-04-03
  • 打赏
  • 举报
回复
这个两个我都查过了。。貌似不能解决列。。

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧