zoukankan      html  css  js  c++  java
  • 取Cookie值

                string url_Login_Group = "http://ui.ptlogin2.qq.com/cgi-bin/login?appid=549000912&daid=5&style=12&s_url=http%3A%2F%2Fqun.qzone.qq.com%2Fgroup%23!%2F336100817%2Fmember";
                string WebCode = GetWebString(url_Login_Group);
                //获取Cookie值
                //string qrsig = Cookies.GetCookies(new Uri("http://ptlogin2.qq.com"))["qrsig"].Value;
                //获取Cookie值
                string uikey = Cookies.GetCookies(new Uri("https://xui.ptlogin2.qq.com"))["uikey"].Value;
                Console.WriteLine(uikey);
                Console.WriteLine(WebCode);
                Console.ReadLine();
    public static CookieContainer Cookies = new CookieContainer();
            public static string GetWebString(string url, string referer = null, Encoding encode = null)
            {
                string webdat = null;
                HttpWebRequest req = null;
                HttpWebResponse res = null;
                try
                {
                    req = (HttpWebRequest)WebRequest.Create(url);
                    req.CookieContainer = Cookies;
                    req.AllowAutoRedirect = false;
                    req.Timeout = 10000;
                    req.Referer = referer;
                    req.Proxy = null;
                    req.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36";
                    res = (HttpWebResponse)req.GetResponse();
                    Cookies.Add(res.Cookies);
                    using (StreamReader reader = new StreamReader(res.GetResponseStream(), encode == null ? Encoding.UTF8 : encode))
                    {
                        webdat = reader.ReadToEnd();
                    }
                    //using (FileStream fs = new FileStream("webdat.txt", FileMode.Create))
                    //{
                    //    byte[] data = Encoding.UTF8.GetBytes(webdat);
                    //    fs.Write(data, 0, data.Length);
                    //}
                }
                catch (HttpException httpex)
                {
                    return "HttpException:" + httpex + "";
                }
                catch (WebException webex)
                {
                    return "WebException:" + webex + "";
                }
                finally
                {
                    if (res != null)
                    {
                        res.Close();
                    }
                    if (req != null)
                    {
                        req.Abort();
                    }
                }
                return webdat;
            }
    View Code
  • 相关阅读:
    语音激活检测(VAD)--前向神经网络方法(Alex)
    语音信号处理基础
    MySQL死锁系列-插入语句正常,但是没有插入成功
    关于wx.getProfile和wx.login获取解密数据偶发失败的原因
    指针访问数组元素
    libev 源码解析
    leveldb 源码--总体架构分析
    raft--分布式一致性协议
    使用springcloud gateway搭建网关(分流,限流,熔断)
    爬虫
  • 原文地址:https://www.cnblogs.com/Zmoli775/p/6589437.html
Copyright © 2011-2022 走看看