Ejemplo n.º 1
0
        public static CookieContainer ExecuteGetCookieAndPic(string url, ref Bitmap sourcebm)
        {
            string content = string.Empty;

            try
            {
                CookieContainer myCookieContainer = new CookieContainer();
                HttpWebRequest  request           = (HttpWebRequest)HttpWebRequest.Create(url);
                HttpWebResponse response          = (HttpWebResponse)request.GetResponse();
                string          cookieStr         = response.Headers["set-cookie"];
                Stream          resStream         = response.GetResponseStream(); //得到验证码数据流
                sourcebm = new Bitmap(resStream);                                 //初始化Bitmap图片
                CookieContainer reList    = new CookieContainer();
                var             cookieVal = Fun.Substring(cookieStr, "=", ";");
                reList.Add(new Cookie("PHPSESSID", cookieVal, "/", "panda.xmxing.net"));
                return(reList);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }