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;
                    }
  • 相关阅读:
    验证SMTP工作过程
    FileZilla FTP服务器的安装和配置
    最后一块石头的重量
    不用加号的加法
    同构字符串
    最长公共子序列
    Telnet 验证HTTP工作过程
    矩阵的最小路径和
    子数组的最大累加和问题
    海思开发板——YOLOv3模型移植(4)
  • 原文地址:https://www.cnblogs.com/shiningrise/p/6124366.html
Copyright © 2011-2022 走看看