示例#1
0
        private void btnGetWebbrowserCookie_Click(object sender, EventArgs e)
        {
            //只能以字符串方式获得
            XJHTTP xjhttp = new XJHTTP();
            string cookie = xjhttp.GetCookieByWininet("https://www.taobao.com");
            HttpHelpers http = new HttpHelpers();
            HttpItems hi = new HttpItems();
            hi = new HttpItems();

            hi.URL = "http://i.taobao.com/my_taobao.htm?spm=a21bo.7724922.1997525045.1.2gOl9t";
            hi.Cookie = cookie;
            hr = http.GetHtml(hi);
            if (hr.Html.Contains("我的淘宝"))
            {
                MessageBox.Show("登录成功");
            }
        }
示例#2
0
文件: Form1.cs 项目: yqMac/regTool
        private void waitforIp(string ip)
        {
            bool retry = true ;
            do
            {
                HttpItems items = new HttpItems();
                items.URL = @"http://www.ip138.com/ips1388.asp";
                //items.ProxyIp = ip;
                items.Cookie = " ";
                //items.ProxyIp = "";
                items.Timeout = 3000;
                HttpResults hr = new HttpHelpers().GetHtml(items);
                //string s = hr.StatusDescription;

                string reHtml = hr.Html.Replace("\r\n", "").Replace("\t", "").Replace("\n", "").Replace(" ", "");
                if (reHtml.Contains("您的IP地址是"))
                {
                    retry = false;
                    reHtml = new XJHTTP().GetStringMid(reHtml, "您的IP地址是:[", "]");
                    //reHtml = new XJHTTP().GetStringMid(reHtml, "[", "");
                }
                else
                {
                    Tsleep(10);
                }
            }
            while (retry);
        }
示例#3
0
        private string[] commandOne(CsdnResouce item, string code = "")
        {
            string[] status = { "模拟评分", "成功/失败", "无验证码", "状态信息", "无附加信息" };
            if (code != "")
            {
                status[2] = "验证码:"+code ;
            }
            hr_com = new HttpHelpers().GetHtml(new HttpItems() {
                URL = "http://download.csdn.net/index.php/comment/get_comment_data/" + item.Id + @"/1?jsonpcallback=jsonp1448000002880&&t=1448000436379",
                Container = cc,
                Referer = item.Url
            } );

            string rehtml = hr_com.Html.Replace("\\r\\n", "").Replace("\\n", "").Replace("\\t", "").Replace(" ", "");
            rehtml = Decode(rehtml);
            Regex regcont=new Regex (@"user_name\\"">(.*?)<\\\/a><\\\/dt><dd>(.*?)<");
            MatchCollection mccont = regcont.Matches(rehtml);
            rehtml = "";
            foreach (Match  m in mccont )
            {
                if (rehtml.Length < m.Groups[2].Value.Length)
                {
                    rehtml = m.Groups[2].Value;
                }
            }
            //getCommandList();
            long epochS = (DateTime.Now.AddSeconds(-5).ToUniversalTime().Ticks - 621355968000000000) / 10000;
            long epochE = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
            //Get评论
            int index = ran.Next(comMsg.Length);
            string commentcon=comMsg [index ]+","+rehtml ;
            string url;

            if ("".Equals(code))
            {
                url = string.Format("http://download.csdn.net/index.php/comment/post_comment?jsonpcallback=jsonp{0}&sourceid={1}&content={2}&rating={3}&t={4}", epochS, item.Id, new XJHTTP().UrlEncoding(item.Name + commentcon ), new Random().Next(3, 6), epochE);
            }
            else
            {
                url = string.Format("http://download.csdn.net/index.php/comment/post_comment?jsonpcallback=jsonp{0}&sourceid={1}&content={2}&txt_validcode={3}&rating={4}&t={5}", epochS, item.Id, new XJHTTP().UrlEncoding(item.Name + commentcon), code, new Random().Next(3, 6), epochE);
            }

            string html = new HttpHelpers().GetHtml(new HttpItems() {
                URL =url ,
                Container =cc
            }).Html;

            //评论成功完成
            if (html.Contains("\"succ\":1"))
            {
                JfCount++;
                status[1] = "成功";
                status[3] = "当前积分:" + JfCount.ToString();
                status[4] = item.Name + comMsg[index];
            }
            else
            {
                status[1] = "失败";
                status[3] = "当前积分:" + JfCount.ToString();

                Regex reg = new Regex("msg\":\"(.+?)\"");
                string msg = new XJHTTP().FromUnicodeString(html);
                MatchCollection mc = reg.Matches(msg);
                if (mc.Count > 0)
                {
                    status[4] = mc[0].Groups[1].Value;
                    //item.Msg = mc[0].Groups[1].Value;
                }
                else
                {
                    status[4] = msg;
                    //item.Msg = msg;
                }

                if ((status[4].Contains("请填写验证码") || status[4].Contains("验证码错误")) && getImgVcode != null)
                {
                    string vcode = getcomVcode("http://download.csdn.net/index.php");
                    if (vcode != "")
                    {
                        return commandOne(item, vcode);
                    }
                }
                else if(msg .Contains ("您因违反"))
                {
                    status[4] = msg;
                    Logscomsole(status );
                    this.Clear();
                    return status;
                }

            }
            return status;
        }
示例#4
0
        private void upload(string filepath,string proxyip="")
        {
            string filename = Path.GetFileName(filepath);

            //获取APC_UPLOAD_PROGRESS
            HttpResults hr_up;
            string rehtml;
            string progress, param1;
            string cookiess = new XJHTTP().CookieTostring(cc);

            hr_up = new HttpHelpers().GetHtml(new HttpItems()
            {
                URL = @"http://u.download.csdn.net/upload",
                Cookie = cookiess
            }, ref cookiess);
            rehtml = hr_up.Html.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "");

            //id="progress_key"value="fdfa65ddb300eaceb54cd1ef425be4cd"
            Regex reg = new Regex("id=\"progress_key\"value=\"(.*?)\"");
            Match mct = reg.Match(rehtml);
            //string s=mct.Groups[1].Value;
            //progress_key" value="
            progress = mct.Groups[1].Value;
            // cookiess += ";dc_session_id="+new XJHTTP ().GetTimeByJs ()+";tos=36;";
            CHECKVCODE:

            //获取验证码
            hr_up = new HttpHelpers().GetHtml(new HttpItems()
            {
                URL = @"http://u.download.csdn.net/index.php/rest/tools/validcode/uploadvalidcode/10.94257339" + new Random().Next().ToString(),
                Referer = "http://u.download.csdn.net/upload",
                Cookie = cookiess,
                ResultType = ResultType.Byte

            }, ref cookiess);
            byte[] imgbytes = hr_up.ResultByte;
            string code = getImgVcode(imgbytes);
            if (code == "")
            {
                return;
            }

            //检查验证码
            hr_up = new HttpHelpers().GetHtml(new HttpItems()
            {
                URL = "http://u.download.csdn.net/index.php/upload/checkform/txt_validcode=" + code,
                Cookie = cookiess,
                Referer = "http://u.download.csdn.net/upload"
            }, ref cookiess);
            rehtml = hr_up.Html.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "");

            if (rehtml != "{\"succ\":1}")
            {
                rehtml = new XJHTTP().FromUnicodeString(rehtml);
                goto CHECKVCODE;
            }
            //上传
            string bundry = "WebKitFormBoundary" + getRandomString(16);

            StringBuilder strb = new StringBuilder();

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"APC_UPLOAD_PROGRESS\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append(progress).Append("\r\n");

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"txt_userfile\"; filename=\"" + filename + "\"").Append("\r\n");
            strb.Append("Content-Type: application/octet-stream").Append("\r\n");
            strb.Append("").Append("\r\n");

            string headerstr = strb.ToString();
            strb.Clear();

            strb.Append("\r\n------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"txt_title\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append("课程资源_"+filename.Substring (1,5) + "_名称").Append("\r\n");

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"sel_filetype\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append("1").Append("\r\n");//改

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"txt_tag\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append(filename .Substring (0,filename .Length >5?5:filename .Length )).Append("\r\n");//改

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"sel_primary\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append("15").Append("\r\n");//改

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"sel_subclass\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append("15013").Append("\r\n");//改

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"sel_score\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append("0").Append("\r\n");//改

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"txt_desc\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append(filename + "资源,需要的下载吧,课程内容进度的保存等" ).Append("\r\n");//改

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"txt_validcode\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append(code).Append("\r\n");//改

            strb.Append("------" + bundry).Append("\r\n");
            strb.Append("Content-Disposition: form-data; name=\"cb_agree\"").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append("").Append("\r\n");
            strb.Append("------" + bundry).Append("--");
            //string headerstr = strb.ToString();
            string tailstr = strb.ToString();

            byte[] heaerbytes = Encoding.ASCII.GetBytes(headerstr);
            byte[] bodybytes = File.ReadAllBytes(filepath);
            byte[] tailbytes = Encoding.ASCII.GetBytes(tailstr);

            byte[] pstdata = ComposeArrays(ComposeArrays(heaerbytes, bodybytes), tailbytes);

            //items_down.Header.Add("Content-Length:"+pstdata .Length );
            hr_up = new HttpHelpers().GetHtml(new HttpItems()
            {
                URL = "http://u.download.csdn.net/upload/do_upload",
                Cookie = cookiess,
                Referer = "http://u.download.csdn.net/upload",
                Method = "post",
                PostDataType = PostDataType.Byte,
                PostdataByte = pstdata,
                Accept = "Accept-Encoding: gzip, deflate",

                ContentType = "multipart/form-data; boundary=----" + bundry,
                ProxyIp =proxyip

            }, ref cookiess);

            rehtml = hr_up.Html.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "");
            if (!rehtml.Contains("uploadkey"))
            {
                //{"succ":0,"errmsg":"\u8bf7\u586b\u5199\u8d44\u6e90\u7684\u6807\u9898!"}
                //{"succ":1,"errmsg":"","uploadkey":"e6a58597b7fd882ff67fe192de62dee8"}
                rehtml = new XJHTTP().FromUnicodeString(rehtml);
                string[] status = { "操作", "成功/失败", "状态信息", "无验证码", "无附加信息" };
                status[0] = "上传文件";
                status[1] = "失败";
                status[2] = filename;
                status[3] = code;
                status[4] = rehtml;
                Logscomsole(status);
            }
            else
            {
                string[] status = { "操作", "成功/失败", "状态信息", "无验证码", "无附加信息" };
                status[0] = "上传文件";
                status[1] = "成功";
                status[2] = filename;
                status[3] = code;
                status[4] = "";
                Logscomsole(status);
            }
        }
示例#5
0
        private void btnGet_Click(object sender, EventArgs e)
        {
            Random r = new Random();
            //初始化Cookie变量
            cc = new System.Net.CookieContainer();
            item = new HttpItems();
            //get 主页
            item.URL = "http://www.mp4ba.com";
            item.Cookie = "__cfduid=123456789; search_state=1463675467;";
            item.UseUnsafe = true;
            hr = http.GetHtml(item);

            string cookie = hr.Cookie;
            XJHTTP xjhttp = new XJHTTP();
            cc = xjhttp.AddCookieToContainer(cc, cookie);
            //get 验证码
            picurl += r.NextDouble();
            item.URL = picurl;
            item.Referer = BaseUrl;
            item.ResultType = ResultType.Byte; //设置返回值类型
            hr = http.GetHtml(item);

            pic.Image = http.GetImg(hr);
        }
示例#6
0
 private void button8_Click(object sender, EventArgs e)
 {
     XJHTTP xj = new XJHTTP();
     item = new HttpItems();
     item.URL = "www.msdn5.com";
     hr = http.GetHtml(item);
     DateTime dt = xj.GetServerTime(hr);  //返回正常格式的时间
     //例如 Date:Sat, 14 Nov 2015 15:55:35 GMT   返回为正常的 2015-11-15 00:21:19 格式
 }
示例#7
0
 private void button9_Click(object sender, EventArgs e)
 {
     XJHTTP xj = new XJHTTP();
     DateTime dt = xj.GetTime4Gmt("Sat, 14 Nov 2015 17:02:33 GMT");
     //这里可以get百度或者get任意一个页面获得datetime对象
     //使用获取的对象为当前电脑校时
     xj.SetLocalTime(DateTime.Now); //使用API设置当前电脑时间
 }
示例#8
0
        private void button6_Click(object sender, EventArgs e)
        {
            CookieContainer cc = new CookieContainer();
            HttpItems items = new HttpItems();
            HttpHelpers helper = new HttpHelpers();
            HttpResults hr = new HttpResults();

            string cookie = "";//字符串方式处理
            items = new HttpItems();
            //items.Container = cc; 自动处理方式
            items.Cookie = cookie;
            items.URL = "http://www.u193.com/opt.php?do=login";
            items.Referer = "http://mrtx.u193.com/";
            items.Method = "Post";
            items.Postdata = "username=ceshiyixia1&password=111111";
            items.Allowautoredirect = true;
            hr = helper.GetHtml(items);

            #region 手动处理字符串Cookie方式
            //hr.Cookie调用时会自动清理cookie 自动剔除无用信息.等同于
            // new XJHTTP().ClearCookie(hr.Cookie);
            cookie = new XJHTTP().UpdateCookie(cookie, hr.Cookie);//手动合并两个Cookie
            #endregion

            #region 自动处理字符串Cookie方式
            //使用ref将cookie传递进方法,每次会自动合并上次与本次返回的cookie
            hr = helper.GetHtml(items, ref cookie);

            #endregion
            //第二次请求
            items = new HttpItems();
            items.URL = "http://mrtx.u193.com/";
            items.Referer = "http://mrtx.u193.com/";
            items.Cookie = cookie;
            //  items.Container = cc; 当cc无法被携带提交失败时使用字符串方式即可
            hr = helper.GetHtml(items);
        }
示例#9
0
 private void button4_Click(object sender, EventArgs e)
 {
     XJHTTP xj = new XJHTTP();
     xj.SetIeCookie("需要设置的URL", "字符串cookie");
     //获取字符串cookie信息方法
     // string cookie = xj.CookieTostring(cc); //从cc对象获得
     // List<Cookie> clist = xj.GetAllCookieByHttpItems(item); //从HttpItems对象获得
     //如果设置失败
     //1 读取旧cookie文件
     StringBuilder cookie = new StringBuilder(new String(' ', 2048));
     int datasize = cookie.Length;
     bool b = XJHTTP.InternetGetCookie("需要读取的URL", null, cookie, ref datasize);
     //删除旧的
     foreach (string fileName in System.IO.Directory.GetFiles(System.Environment.GetFolderPath(Environment.SpecialFolder.Cookies)))
     {
         if (fileName.ToLower().IndexOf("需要删除的URL") > 0)
         {
             System.IO.File.Delete("需要删除的URL");
         }
     }
     //生成新的
     foreach (string c in "新cookie".Split(';'))
     {
         //重组COOKIE信息
         string[] item = c.Split('=');
         string name = item[0];
         string value = item[1] + ";expires=Sun,22-Feb-2099 00:00:00 GMT";
         XJHTTP.InternetSetCookie("需要设置的URL", name, value);
         XJHTTP.InternetSetCookie("需要设置的URL", name, value);
         XJHTTP.InternetSetCookie("需要设置的URL", name, value);
     }
     //完成后调用IE打开即可
     xj.OpenUrl("需要设置的URL");
     //或者webbrowser中打开
     webBrowser1.Navigate("需要设置的URL");
 }
示例#10
0
 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         XJHTTP xj = new XJHTTP();
         xj.ClearIECookie();
     }
     catch (Exception)
     {  //如果清除发生异常,请在这里捕获
         throw;
     }
 }
示例#11
0
 private void button2_Click(object sender, EventArgs e)
 {
     XJHTTP xjhttp = new XJHTTP();
     CookieContainer cc = new CookieContainer();
     string referer = "www.msdn5.com"; //上一次请求地址
     string postdata = "这里是提交的数据"; //post提交数据
     HttpResults hr = xjhttp.PostHtml(PostUrl, referer, postdata, true, cc);
 }
示例#12
0
        private void button1_Click(object sender, EventArgs e)
        {
            XJHTTP xjhttp = new XJHTTP();
            string strall = "input type=\"hidden\" name=\"uuid\" value=\"0018h2ZztdI-jKb-\">";
            List<string> s = xjhttp.GetStringMids(strall, "value=\"", "\"");
            string str = xjhttp.GetStringMid(strall, "value=\"", "\"");
            string s1 = xjhttp.GetMidHtml(strall, "value=\"", "\"");

            CookieContainer cc = new CookieContainer();
            HttpResults hr = xjhttp.GetHtml(BaseUrl, cc);
            txtInfo.Text = hr.Html;
        }