.NET (c#) 模拟 Cookie

string postData = "uUsername=avoid&uPassword=123456";
                    ASCIIEncoding encoding = new ASCIIEncoding();
                    byte[] data = encoding.GetBytes(postData);

                    request = (HttpWebRequest)WebRequest.Create(sUrl);
                    request.Method = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.ContentLength = data.Length;
                    Stream newStream = request.GetRequestStream();
                    newStream.Write(data, 0, data.Length);

                    newStream.Close();
                   
                    request.CookieContainer = cc;
                   
                    response = (HttpWebResponse)request.GetResponse();
                    cc.Add(response.Cookies);
                    stream = response.GetResponseStream();
                    sHtml = new StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();
        private CookieContainer cc = new CookieContainer();

posted @ 2009-11-10 10:55  kenter  阅读(386)  评论(0编辑  收藏  举报