求高手帮忙解决 c# 模拟登录带验证码 总提示验证码错误

yourname386 2015-03-19 06:04:37
c# 模拟登录带验证码 总提示验证码错误,这个网站以前没有加验证码的时候时可以正常模拟登录进去的。

这是以前的代码:
string str_ratk = "";
double dttick = this.cConvertDateTimeInt(System.DateTime.Now);
result = HttpHelper.GetHtml("http://www.plateno.com/p/nlogin.html?_=" + dttick.ToString() + "");
Regex rgeratk = new Regex(@"ratk""\s\w*=""\w*"">", RegexOptions.Compiled); // ratk"\s\w*="\w*">
Match mratk = rgeratk.Match(result);
str_ratk = mratk.Groups[0].ToString().Trim();
str_ratk = cGetStringBetween(str_ratk, "value=\"", "\">");

result = "";
postData = "fromType=0&username=13535127593&password=a111111&atk=" + str_ratk.Trim() + "&j_expiredays=0&passwordType=0";
result = HttpHelper.GetHtml("http://www.plateno.com/ajax_authentication", postData, true, HttpHelper.CookieContainer);

网站加了验证码后参考了一些网友的做法,但总是提示 “验证码错误”
...全文
394 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
本拉灯 2015-03-28
  • 打赏
  • 举报
回复
你要先用HttpRequest访问取验证码地址,然后用这个Cookies取登录的页面,然后取到Hidden里的特殊值与Cookies 最后把上面的Cookies一起打包发送请求就可以了。
失落的神庙 2015-03-28
  • 打赏
  • 举报
回复

 public static string doPost(string Url, byte[] postData, QQCookie bCookie, String encodingFormat, String referer, string ProxyStr)
        {
                try
                {
                    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
                    if (ProxyStr != ""&&ProxyStr != null)
                    {
                        //设置代理
                        WebProxy proxy = new WebProxy();
                        proxy.Address = new Uri(ProxyStr);
                        myRequest.UseDefaultCredentials = true;
                        myRequest.Proxy = proxy;
                    }
                    //myRequest.ServicePoint.Expect100Continue = false;
                    myRequest.CookieContainer = bCookie.mycookie;
                    myRequest.Method = "POST";
                    myRequest.Timeout = 30000;
                    myRequest.KeepAlive = true;//modify by yang
                    if (referer != "")
                        myRequest.Referer = referer;
                    myRequest.Headers["Cache-control"] = "no-cache";//.CachePolicy = .c "no-cache";//["Cache-control: no-cache"]
                    myRequest.Headers["Accept-Language"] = "zh-cn";
                    myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Trident/4.0; GTB7.4; GTB7.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)";
                    myRequest.ContentType = "application/x-www-form-urlencoded";
                    myRequest.Accept = "*/*";
                    myRequest.ContentLength = postData.Length;

                    //setRequestHeader(requestHearder, myRequest);

                    Stream newStream = myRequest.GetRequestStream();
                    newStream.Write(postData, 0, postData.Length);
                    newStream.Close();
                    //if (waitTime != 0)
                    //    Thread.Sleep(waitTime);
                    HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                    bCookie.upcookie(myResponse.Cookies);
                    StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding(encodingFormat));
                    string outdata = reader.ReadToEnd();
                    reader.Close();
                    if (!outdata.Contains("基础连接已经关闭: 连接被意外关闭") && !outdata.Contains("无法连接到远程服务器") && !outdata.Contains("基础连接已经关闭: 接收时发生错误。"))
                        return outdata;
                    else
                        return "基础连接已经关闭: 连接被意外关闭";

                }
                catch (Exception ex)
                {
                    if (!ex.Message.Contains("基础连接已经关闭: 连接被意外关闭") && !ex.Message.Contains("无法连接到远程服务器") && !ex.Message.Contains("基础连接已经关闭: 接收时发生错误。"))
                        return ex.Message;
                    else
                        return "基础连接已经关闭: 连接被意外关闭";
                }

        }

  public static string doGet(string Url, QQCookie bCookie, String encodingFormat, String refUrl, string ProxyStr)
        {
            try
            {
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
                if (ProxyStr != ""&&ProxyStr != null)
                {
                    //设置代理
                    WebProxy proxy = new WebProxy();
                    proxy.Address = new Uri(ProxyStr);
                    myRequest.UseDefaultCredentials = true;
                    myRequest.Proxy = proxy;
                }
                myRequest.ServicePoint.Expect100Continue = true;
                myRequest.CookieContainer = bCookie.mycookie;
                myRequest.Method = "GET";
                if (refUrl != null && refUrl != string.Empty)
                    myRequest.Referer = refUrl;
                myRequest.Timeout = 6000;
                myRequest.KeepAlive = true;//modify by yang
                myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)";
                myRequest.ContentType = "application/x-www-form-urlencoded";

                //setRequestHeader(requestHeaders, myRequest);

                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                //string dddd = myResponse.Headers["Set-Cookie"];
                bCookie.upcookie(myResponse.Cookies);
                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding(encodingFormat));
                string outdata = reader.ReadToEnd();
                reader.Close();
                return outdata;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

 public static Image doGetImg(string Url, QQCookie bCookie, string ProxyStr)
        {
            try
            {
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
                if (ProxyStr != ""&&ProxyStr != null)
                {
                    //设置代理
                    WebProxy proxy = new WebProxy();
                    proxy.Address = new Uri(ProxyStr);
                    myRequest.UseDefaultCredentials = true;
                    myRequest.Proxy = proxy;
                }
                myRequest.ServicePoint.Expect100Continue = true;
                myRequest.CookieContainer = bCookie.mycookie;
                myRequest.Method = "GET";
                //if (!CommonTool.isEmpty(refUrl))
                myRequest.Timeout = 6000;
                myRequest.KeepAlive = true;//modify by yang
                myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                bCookie.upcookie(myResponse.Cookies);
                return Bitmap.FromStream(myResponse.GetResponseStream());
            }
            catch //(Exception ex)
            {
                return null;
            }
        }

 public class QQCookie
    {
        public CookieContainer mycookie = new CookieContainer();//定义cookie容器
        public Object obj = new Object();
        public byte[] byt = new byte[1];
        public void upcookie(CookieCollection cookie)
        {
            for (int i = 0; i < cookie.Count; i++)
            {
                mycookie.Add(cookie[i]);
            }
            obj = mycookie;
            byt = ObjectToBytes(obj);
        }
        /**/
        /// <summary>
        /// 将一个object对象序列化,返回一个byte[]
        /// </summary>
        /// <param name="obj">能序列化的对象</param>
        /// <returns></returns>
        public static byte[] ObjectToBytes(object obj)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(ms, obj);
                return ms.GetBuffer();
            }
        }

        /**/
        /// <summary>
        /// 将一个序列化后的byte[]数组还原
        /// </summary>
        /// <param name="Bytes"></param>
        /// <returns></returns>
        public object BytesToObject(byte[] Bytes)
        {
            using (MemoryStream ms = new MemoryStream(Bytes))
            {
                IFormatter formatter = new BinaryFormatter();
                return formatter.Deserialize(ms);
            }
        }
        public CookieContainer getcookie()
        {
            return mycookie;
        }
    }

yourname386 2015-03-28
  • 打赏
  • 举报
回复
引用 7 楼 wawd74520 的回复:
sc=new SinaCookie(); doGet("http://www.plateno.com/p/nloginxxxxxxxxxx",sc); //登录界面 去atk doGetImg("http://www.plateno.com/imageToken?id=lgCheckcode&r=0.6810257183387876",sc);//验证码获取 dopost。。。。登录 类似这样。 如果你有我的那些类。 sc传进去 Cookie会自动更新。。。
我的大概思路也是这样子,但还是不行,能不能把你的类发一份给我参考一下?感谢! yourname386@163.com
失落的神庙 2015-03-28
  • 打赏
  • 举报
回复
这种网站没这么简单的。 去把head 什么的都弄弄。 Cookie 弄成stringCookie 一个个取 。
yourname386 2015-03-28
  • 打赏
  • 举报
回复
引用 10 楼 wyd1520 的回复:
你要先用HttpRequest访问取验证码地址,然后用这个Cookies取登录的页面,然后取到Hidden里的特殊值与Cookies 最后把上面的Cookies一起打包发送请求就可以了。
这句怎么理解? 然后取到Hidden里的特殊值与Cookies 最后把上面的Cookies一起打包发送请求就可以了
yourname386 2015-03-28
  • 打赏
  • 举报
回复
引用 9 楼 wawd74520 的回复:

 public static string doPost(string Url, byte[] postData, QQCookie bCookie, String encodingFormat, String referer, string ProxyStr)
        {
                try
                {
                    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
                    if (ProxyStr != ""&&ProxyStr != null)
                    {
                        //设置代理
                        WebProxy proxy = new WebProxy();
                        proxy.Address = new Uri(ProxyStr);
                        myRequest.UseDefaultCredentials = true;
                        myRequest.Proxy = proxy;
                    }
                    //myRequest.ServicePoint.Expect100Continue = false;
                    myRequest.CookieContainer = bCookie.mycookie;
                    myRequest.Method = "POST";
                    myRequest.Timeout = 30000;
                    myRequest.KeepAlive = true;//modify by yang
                    if (referer != "")
                        myRequest.Referer = referer;
                    myRequest.Headers["Cache-control"] = "no-cache";//.CachePolicy = .c "no-cache";//["Cache-control: no-cache"]
                    myRequest.Headers["Accept-Language"] = "zh-cn";
                    myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Trident/4.0; GTB7.4; GTB7.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)";
                    myRequest.ContentType = "application/x-www-form-urlencoded";
                    myRequest.Accept = "*/*";
                    myRequest.ContentLength = postData.Length;

                    //setRequestHeader(requestHearder, myRequest);

                    Stream newStream = myRequest.GetRequestStream();
                    newStream.Write(postData, 0, postData.Length);
                    newStream.Close();
                    //if (waitTime != 0)
                    //    Thread.Sleep(waitTime);
                    HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                    bCookie.upcookie(myResponse.Cookies);
                    StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding(encodingFormat));
                    string outdata = reader.ReadToEnd();
                    reader.Close();
                    if (!outdata.Contains("基础连接已经关闭: 连接被意外关闭") && !outdata.Contains("无法连接到远程服务器") && !outdata.Contains("基础连接已经关闭: 接收时发生错误。"))
                        return outdata;
                    else
                        return "基础连接已经关闭: 连接被意外关闭";

                }
                catch (Exception ex)
                {
                    if (!ex.Message.Contains("基础连接已经关闭: 连接被意外关闭") && !ex.Message.Contains("无法连接到远程服务器") && !ex.Message.Contains("基础连接已经关闭: 接收时发生错误。"))
                        return ex.Message;
                    else
                        return "基础连接已经关闭: 连接被意外关闭";
                }

        }

  public static string doGet(string Url, QQCookie bCookie, String encodingFormat, String refUrl, string ProxyStr)
        {
            try
            {
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
                if (ProxyStr != ""&&ProxyStr != null)
                {
                    //设置代理
                    WebProxy proxy = new WebProxy();
                    proxy.Address = new Uri(ProxyStr);
                    myRequest.UseDefaultCredentials = true;
                    myRequest.Proxy = proxy;
                }
                myRequest.ServicePoint.Expect100Continue = true;
                myRequest.CookieContainer = bCookie.mycookie;
                myRequest.Method = "GET";
                if (refUrl != null && refUrl != string.Empty)
                    myRequest.Referer = refUrl;
                myRequest.Timeout = 6000;
                myRequest.KeepAlive = true;//modify by yang
                myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)";
                myRequest.ContentType = "application/x-www-form-urlencoded";

                //setRequestHeader(requestHeaders, myRequest);

                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                //string dddd = myResponse.Headers["Set-Cookie"];
                bCookie.upcookie(myResponse.Cookies);
                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding(encodingFormat));
                string outdata = reader.ReadToEnd();
                reader.Close();
                return outdata;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

 public static Image doGetImg(string Url, QQCookie bCookie, string ProxyStr)
        {
            try
            {
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
                if (ProxyStr != ""&&ProxyStr != null)
                {
                    //设置代理
                    WebProxy proxy = new WebProxy();
                    proxy.Address = new Uri(ProxyStr);
                    myRequest.UseDefaultCredentials = true;
                    myRequest.Proxy = proxy;
                }
                myRequest.ServicePoint.Expect100Continue = true;
                myRequest.CookieContainer = bCookie.mycookie;
                myRequest.Method = "GET";
                //if (!CommonTool.isEmpty(refUrl))
                myRequest.Timeout = 6000;
                myRequest.KeepAlive = true;//modify by yang
                myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                bCookie.upcookie(myResponse.Cookies);
                return Bitmap.FromStream(myResponse.GetResponseStream());
            }
            catch //(Exception ex)
            {
                return null;
            }
        }

 public class QQCookie
    {
        public CookieContainer mycookie = new CookieContainer();//定义cookie容器
        public Object obj = new Object();
        public byte[] byt = new byte[1];
        public void upcookie(CookieCollection cookie)
        {
            for (int i = 0; i < cookie.Count; i++)
            {
                mycookie.Add(cookie[i]);
            }
            obj = mycookie;
            byt = ObjectToBytes(obj);
        }
        /**/
        /// <summary>
        /// 将一个object对象序列化,返回一个byte[]
        /// </summary>
        /// <param name="obj">能序列化的对象</param>
        /// <returns></returns>
        public static byte[] ObjectToBytes(object obj)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(ms, obj);
                return ms.GetBuffer();
            }
        }

        /**/
        /// <summary>
        /// 将一个序列化后的byte[]数组还原
        /// </summary>
        /// <param name="Bytes"></param>
        /// <returns></returns>
        public object BytesToObject(byte[] Bytes)
        {
            using (MemoryStream ms = new MemoryStream(Bytes))
            {
                IFormatter formatter = new BinaryFormatter();
                return formatter.Deserialize(ms);
            }
        }
        public CookieContainer getcookie()
        {
            return mycookie;
        }
    }

加了你的类,还是验证码不正确 QQCookie sc ; string str_ratk = ""; private void btn_Pic_Click(object sender, EventArgs e) { sc = new QQCookie(); double dttick = this.cConvertDateTimeInt(System.DateTime.Now); string result = ""; result = "http://www.plateno.com/p/nlogin.html?_=" + dttick.ToString() + ""; result = doGet(result, sc, "utf-8", "", ""); //登录界面 去atk // Regex rgeratk = new Regex(@"ratk""\s\w*=""\w*"">", RegexOptions.Compiled); // ratk"\s\w*="\w*"> Match mratk = rgeratk.Match(result); str_ratk = mratk.Groups[0].ToString().Trim(); str_ratk = cGetStringBetween(str_ratk, "value=\"", "\">"); this.btn_Pic.Visible = false; this.btn_Pic.Image = doGetImg("http://www.plateno.com/imageToken?id=lgCheckcode&r=0.6810257183387876", sc, ""); this.btn_Pic.Visible = true; } private void btn_tb_Click(object sender, EventArgs e) { string postData = ""; string result = ""; strUser = "13535080156"; //13535127593 userPWD = "a111111"; //postData = "fromType=0&username=" + strUser.Trim() + "&password=" + userPWD + "&lgCheckcode=" + txt_code.Text.Trim() + "&atk=" + str_ratk.Trim() + "&j_expiredays=0&passwordType=0"; postData = "fromType=0&username=13535127593&password=a1&lgCheckcode=" + txt_code.Text.Trim() + "&atk=" + str_ratk.Trim() + "&j_expiredays=0&passwordType=0"; byte[] data = System.Text.Encoding.UTF8.GetBytes(postData); result = doPost("http://www.plateno.com/ajax_authentication", data, sc, "utf-8","http://www.plateno.com/login.html?from=sso",""); txt_textcode.Text = result; //提示:验证码不正确 }
yourname386 2015-03-26
  • 打赏
  • 举报
回复
引用 3 楼 wawd74520 的回复:
一看就知道 atk 是验证码相关。 你atk 是固定了。 你必须先去登录页面采集这个atk 然后 去获取验证码。 然后 提交。
这个 atk 的值我是为了调试方便固定了一下,实际上是每次都有去取这个atk的值,但把这个atk的值加上去后还是报验证码不正确,在帖子的内容里有加atk的,但不知道为什么总是不成功
失落的神庙 2015-03-26
  • 打赏
  • 举报
回复
sc=new SinaCookie(); doGet("http://www.plateno.com/p/nloginxxxxxxxxxx",sc); //登录界面 去atk doGetImg("http://www.plateno.com/imageToken?id=lgCheckcode&r=0.6810257183387876",sc);//验证码获取 dopost。。。。登录 类似这样。 如果你有我的那些类。 sc传进去 Cookie会自动更新。。。
zj_zwl 2015-03-20
  • 打赏
  • 举报
回复
获取验证码时有时会返回cookie,提交的时候要带上. 代码好乱,看的头疼
泡泡龙 2015-03-20
  • 打赏
  • 举报
回复
用fiddler抓包比较几次,看看post的字符串构造对不对 如果构造正确,那么就检查headers,看看有没有防盗链处理
失落的神庙 2015-03-20
  • 打赏
  • 举报
回复


一看就知道 atk 是验证码相关。 你atk 是固定了。 你必须先去登录页面采集这个atk
然后 去获取验证码。
然后 提交。
yourname386 2015-03-20
  • 打赏
  • 举报
回复
没打算用程序去识别验证码,我是想把验证码取到后显示出来,然后用手工输入验证吗, 为什么这个网站总是提示验证码不正确?我试了一下其它的网站是可以的,不知道这个网站为什么不行 //取回验证码 private void btn_Pic_Click(object sender, EventArgs e) { this.btn_Pic.Image = doGetImg("http://www.plateno.com/imageToken?id=lgCheckcode&r=0.6810257183387876",sc); } //下面是登录, 这里面有个时间戳要处理一下 private void btn_login_Click(object sender, EventArgs e) { string postData = "fromType=0&username=13535080156&password=a111111&lgCheckcode=" + txt_code.Text.Trim() + "&atk=7d2f360f00fe4614bb503d9c2dd0f5a9&j_expiredays=0&passwordType=0"; byte[] data = System.Text.Encoding.UTF8.GetBytes(postData); string result = doPost("http://www.plateno.com/ajax_authentication", data, sc, "utf-8", "http://www.plateno.com/login.html?from=sso"); } // public static Image doGetImg(string Url, TestCookie bCookie) { try { HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString()); myRequest.ServicePoint.Expect100Continue = true; myRequest.CookieContainer = bCookie.mycookie; myRequest.Method = "GET"; myRequest.Timeout = 30000; myRequest.KeepAlive = true;//modify by yang myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"; myRequest.ContentType = "application/x-www-form-urlencoded"; HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); bCookie.upcookie(myResponse.Cookies); return Bitmap.FromStream(myResponse.GetResponseStream()); } catch { return null; } } public static string doPost(string Url, byte[] postData, TestCookie bCookie, String encodingFormat, String referer) { try { HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString()); myRequest.CookieContainer = bCookie.mycookie; myRequest.Method = "POST"; myRequest.Timeout = 30000; myRequest.KeepAlive = true; if (referer != "") myRequest.Referer = referer; myRequest.Headers["Cache-control"] = "no-cache"; myRequest.Headers["Accept-Language"] = "zh-cn"; myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Trident/4.0; GTB7.4; GTB7.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.Accept = "*/*"; if (postData != null) { myRequest.ContentLength = postData.Length; Stream newStream = myRequest.GetRequestStream(); newStream.Write(postData, 0, postData.Length); newStream.Close(); } HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); bCookie.upcookie(myResponse.Cookies); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding(encodingFormat)); string outdata = reader.ReadToEnd(); reader.Close(); if (!outdata.Contains("基础连接已经关闭: 连接被意外关闭") && !outdata.Contains("无法连接到远程服务器") && !outdata.Contains("基础连接已经关闭: 接收时发生错误。")) return outdata; else return "基础连接已经关闭: 连接被意外关闭"; } catch (Exception ex) { if (!ex.Message.Contains("基础连接已经关闭: 连接被意外关闭") && !ex.Message.Contains("无法连接到远程服务器") && !ex.Message.Contains("基础连接已经关闭: 接收时发生错误。")) return ex.Message; else return "基础连接已经关闭: 连接被意外关闭"; } } public class TestCookie { public CookieContainer mycookie = new CookieContainer();//定义cookie容器 public Object obj = new Object(); public byte[] byt = new byte[1]; public void upcookie(CookieCollection cookie) { for (int i = 0; i < cookie.Count; i++) { mycookie.Add(cookie[i]); } obj = mycookie; byt = ObjectToBytes(obj); } /**/ /// <summary> /// 将一个object对象序列化,返回一个byte[] /// </summary> /// <param name="obj">能序列化的对象</param> /// <returns></returns> public static byte[] ObjectToBytes(object obj) { using (MemoryStream ms = new MemoryStream()) { IFormatter formatter = new BinaryFormatter(); formatter.Serialize(ms, obj); return ms.GetBuffer(); } } /**/ /// <summary> /// 将一个序列化后的byte[]数组还原 /// </summary> /// <param name="Bytes"></param> /// <returns></returns> public object BytesToObject(byte[] Bytes) { using (MemoryStream ms = new MemoryStream(Bytes)) { IFormatter formatter = new BinaryFormatter(); return formatter.Deserialize(ms); } } public CookieContainer getcookie() { return mycookie; } } TestCookie sc = new TestCookie();
泡泡龙 2015-03-19
  • 打赏
  • 举报
回复
验证码不会识别的话,那肯定是错误的。除非网站给留后门

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧