基本信息
源码名称:C# QQ自动注册机 实例源码
源码大小:0.99M
文件格式:.zip
开发语言:C#
更新时间:2014-11-27
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

自动填表,获取验证码,保持cookie

//sPostData,待提交的数据串,如http://www.test.com/login.aspx?user=admin&pwd=123456
        public static CookieContainer Login(string url, string sPostData, CookieContainer cc)
        {
            CookieContainer container = (cc == null) ? new CookieContainer() : cc;
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(sPostData);

            HttpWebRequest resquest = ResquestInit(url);
            resquest.Method = "POST";
            resquest.ContentLength = data.Length;
            resquest.CookieContainer = container;

            Stream newStream = resquest.GetRequestStream();
            newStream.Write(data, 0, data.Length);
            newStream.Close();
            try
            {
                HttpWebResponse response = (HttpWebResponse)resquest.GetResponse();
                response.Cookies = container.GetCookies(resquest.RequestUri);
            }
            catch { }

            return container;
        }
        //这个函数的作用就是统一Request的格式,使得每次访问目标网站都用相同的口径。如果参数不同的话,可能造成COOKIE无效,因而登录无效
        public static HttpWebRequest ResquestInit(string url)
        {
            Uri target = new Uri(url);
            HttpWebRequest resquest = (HttpWebRequest)WebRequest.Create(target);
            resquest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2 (.NET CLR 3.5.30729)";
            resquest.Accept = "text/html,application/xhtml xml,application/xml;q=0.9,*/*;q=0.8";
            resquest.AllowAutoRedirect = true;
            resquest.KeepAlive = true;
            resquest.ReadWriteTimeout = 120000;
            resquest.ContentType = "application/x-www-form-urlencoded";
            resquest.Referer = url;

            return resquest;
        }