zoukankan      html  css  js  c++  java
  • C# HttpWebRequest获取COOKIES

    C# HttpWebRequest获取COOKIES

    byte[] bytes = Encoding.Default.GetBytes(_post);
                    CookieContainer myCookieContainer = new CookieContainer();
                    try
                    {
                        //新建一个CookieContainer
                        HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(_loginurl);
                        //新建一个HttpWebRequest
                        myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
                        myHttpWebRequest.AllowAutoRedirect = false;
                        myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
                        myHttpWebRequest.Timeout = 60000;
                        myHttpWebRequest.KeepAlive = true;
                        myHttpWebRequest.ContentLength = bytes.Length;
                        myHttpWebRequest.Method = "POST";
                        myHttpWebRequest.CookieContainer = myCookieContainer;
                        //设置HttpWebRequest
                        Stream myRequestStream = myHttpWebRequest.GetRequestStream();
                        myRequestStream.Write(bytes, 0, bytes.Length);
                        myRequestStream.Close();
                        HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                        foreach (Cookie ck in myHttpWebResponse.Cookies)
                        {
                            myCookieContainer.Add(ck);
                        }
                        myHttpWebResponse.Close();
                    }
                    catch
                    {
                        MessageBox.show("获取COOKIES失败!");
                        return;
                    }
  • 相关阅读:
    flex
    IOCP三:多个接收
    IOCP三:多个接收
    IOCP二:同时发送和接收
    IOCP二:同时发送和接收
    IOCP一:AcceptEx
    IOCP一:AcceptEx
    字符串和数字相互转换
    字符串和数字相互转换
    QThread应用详解
  • 原文地址:https://www.cnblogs.com/shiningrise/p/6124366.html
Copyright © 2011-2022 走看看