日期:2014-05-18  浏览次数:20926 次

如何清除cookies






C# code

  string url2 = "http://www.XXXX.com/user.php";
            request = (HttpWebRequest)WebRequest.Create(url2 + "?" + new Random().NextDouble());
            request.CookieContainer = container;
            
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = param.Length;
            request.Method = "POST";
            Stream myRequestStream = request.GetRequestStream();
            StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
            myStreamWriter.Write(param);
            //把数据写入HttpWebRequest的Request流
            myStreamWriter.Close();
            myRequestStream.Close();
            //关闭打开对象
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)request.GetResponse();
            //新建一个HttpWebResponse
            myHttpWebResponse.Cookies = container.GetCookies(request.RequestUri);
            //获取一个包含url的Cookie集合的CookieCollection
            Stream myResponseStream = myHttpWebResponse.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string outdata = myStreamReader.ReadToEnd();
            //把数据从HttpWebResponse的Response流中读出
            myStreamReader.Close();
            myResponseStream.Close();





请问我要清除上面代码的cookies,如何清除?

------解决方案--------------------
时间设置成过去的一个值,参考:http://topic.csdn.net/u/20110415/16/6b444f97-cd30-47dc-bed7-3e885169057c.html
------解决方案--------------------
当然上面只是简单的操作cookie 还有子键的方法 
参考
http://www.cnblogs.com/Leo_wl/archive/2010/04/26/1721642.html
------解决方案--------------------
request.CookieContainer = container;

new一个cookiecontainer就会产生新的,httpwebrequest不需要清除的.