Esempio n. 1
0
        public ReturnMsgDC ExecRequest(string targetFile, Hashtable htbParams)
        {
            string baseUrl = DCConf.GetDCUrl(this.ProdType, this.MethodType);
            string url     = $"{ baseUrl.TrimEnd('/')}/{targetFile}";

            if (htbParams != null && htbParams.Count > 0)
            {
                List <string> lstValues = new List <string>();
                foreach (string key in htbParams.Keys)
                {
                    lstValues.Add($"{key}={htbParams[key]}");
                }
                url = $"{url}?{ string.Join("&", lstValues.ToArray())}";
            }
            HttpComm comm = new HttpComm();
            Dictionary <string, string> dicRequestParams = new Dictionary <string, string>();

            dicRequestParams.Add("url", url);
            HttpResult result = comm.ExecWebRequest(dicRequestParams);

            if (result.IsSucceed)
            {
                return(this.ResolveD2(result.Content));
            }
            else
            {
                throw new Exception("请求DC发生异常", result.HttpException);
            }
        }
Esempio n. 2
0
 public void RequestApi()
 {
     _thread01 = new Thread(() =>
     {
         var apiUrl        = String.Format(StaticResources.ZHIHU_QUESTION_API, tb_question.Text, 20, 0);
         HttpComm httpComm = new HttpComm();
         httpComm.Cookies  = _cookieContainers;
         while (true)
         {
             try
             {
                 httpComm.Request(apiUrl);
                 var res     = new string(Encoding.UTF8.GetChars(httpComm.ResponseBts));
                 var jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject <ResJsonResponse>(res);
                 //data是否有数据
                 if (jsonObj.data != null && jsonObj.data.Count > 0)
                 {
                     for (int i = 0; i < jsonObj.data.Count; i++)
                     {
                         var url = string.Format(StaticResources.ZHIHU_ANSWER_API, _question, jsonObj.data[i].id);
                         _urls.Enqueue(Tuple.Create(url, jsonObj.data[i].Copy()));
                     }
                     Invoke(new MethodInvoker(delegate()
                     {
                         rtb_msg.Text = "RequestApi:" + apiUrl + "(" + jsonObj.data.Count + ")" + "\r\n" + rtb_msg.Text;
                     }));
                     apiUrl = jsonObj.paging.next;
                 }
                 else
                 {
                     break;
                 }
             }
             catch (Exception ex)
             {
                 Invoke(new MethodInvoker(delegate()
                 {
                     rtb_errorMsg.Text = "RequestApi:" + ex.Message + "\r\n" + rtb_errorMsg.Text;
                 }));
                 break;
             }
         }
         Invoke(new MethodInvoker(delegate()
         {
             rtb_msg.Text = "RequestApi[done]" + _urls.Count.ToString() + "\r\n" + rtb_msg.Text;
         }));
     });
     _thread01.Start();
 }
Esempio n. 3
0
        public ReturnMsgListDC ExecRequestList(string targetFile, Hashtable htbParams)
        {
            string baseUrl = DCConf.GetDCUrl(this.ProdType, this.MethodType);
            string url     = $"{ baseUrl.TrimEnd('/')}/{targetFile}";

            if (htbParams != null && htbParams.Count > 0)
            {
                List <string> lstValues = new List <string>();
                foreach (string key in htbParams.Keys)
                {
                    lstValues.Add($"{key}={htbParams[key]}");
                }
                url = $"{url}?{ string.Join("&", lstValues.ToArray())}";
            }
            HttpComm comm = new HttpComm();
            Dictionary <string, string> dicRequestParams = new Dictionary <string, string>();

            dicRequestParams.Add("url", url);
            HttpResult result = comm.ExecWebRequest(dicRequestParams);

            if (result.IsSucceed)
            {
                string[]           strArray = result.Content.Split("\n".ToCharArray());
                int                code     = -1;
                List <CLSObject[]> data     = new List <CLSObject[]>();
                for (int i = 0; i < strArray.Length; i++)
                {
                    string[] strArray2 = strArray[i].Split(",".ToCharArray());
                    if ((i == 0) && (strArray2.Length >= 1))
                    {
                        code = int.Parse(strArray2[0]);
                    }
                    CLSObject[] item = new CLSObject[strArray2.Length];
                    for (int j = 0; j < strArray2.Length; j++)
                    {
                        item[j] = strArray2[j];
                    }
                    data.Add(item);
                }
                return(new DC.ReturnMsgListDC(true, result.Content, code, data));
            }
            else
            {
                throw new Exception("请求DC发生异常", result.HttpException);
            }
        }
        private async Task ExecuteCommandAsync(Command command, int percentValue = 0)
        {
            var prefsInfo = new PrefsInfo(Prefs);

            if (prefsInfo.IsReady)
            {
                try
                {
                    var url = FormatCommandResource(prefsInfo.Host, prefsInfo.Port, command, percentValue.Clamp(0, 100));
                    await HttpComm.Request()
                    .WithContentType(HttpContentType.Html)
                    .WithMethod(HttpMethod.Get)
                    .WithUrl(url)
                    .ExecuteAsync();
                }
                catch (Exception) { }
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var httpCommunication = new HttpComm();
            var response          = httpCommunication.Execute(UrlList.PetsUrl, null, "GET", "application/json", typeof(List <Person>));


            if (!(response is List <Person>))
            {
                Console.WriteLine($"Response is not of desired type!");
            }

            var typedResponse = ((List <Person>)response).ToList();

            DataManip dataManip = new DataManip();

            dataManip.GetAllCats(typedResponse, true);

            Console.WriteLine("press any key...");
            Console.ReadKey();
        }
Esempio n. 6
0
        // 检查普通验证码是否正常
        public static ReturnMsg Func_CheckSmsCode(int number, string telnum, string smscode)
        {
            string     baseUrl    = DC2Conf.MPFUrlHeader;
            string     isProg     = DC2Conf.IsProg.ToString();
            string     url        = $"{baseUrl}&&isprog={isProg}&action=checkcode&number={number}&telnum={telnum}&code={smscode}";
            HttpComm   comm       = new HttpComm();
            HttpResult httpResult = comm.ExecWebRequest(url);

            //string urltext = CLSTemplate.Transform2(urlformat, cht_data);
            //CLSInterfaceReturn cir = new CLSInterfaceReturn().initWithContentsOfURL(urltext);
            //return Operator.RetFor(cir.Succeed, cir.Message, cir.Code);

            if (httpResult.IsSucceed)
            {
                return(new ReturnMsg2980(httpResult.Content));
            }
            else
            {
                throw httpResult.HttpException;
            }
        }
Esempio n. 7
0
        public void Not_Found_404() // 27.12.2016. 01:11:02>           AdReader05: Greška: Neuspelo čitanje strane sa adrese http://www.polovniautomobili.com/putnicka-vozila/9279240/peugeot-407-20-hdi-ful-oprema. Pokušaj 1/3. Exception: Object reference not set to an instance of an object.. StackTrace:    at Procode.PolovniAutomobili.Common.Http.Strana.Procitaj() in C:\Users\Nemanja\Source\Repos\polovni-automobili\Common\Http\Strana.cs:line 38
        {
            string adAddress = "http://www.polovniautomobili.com/putnicka-vozila/9279240/peugeot-407-20-hdi-ful-oprema";
            string exceptionMessage;
            var    x = HttpComm.GetPage(adAddress, out exceptionMessage);

            if (x != null)
            {
                string adContent = x.ToString();

                Model.Vehicle.Automobile automobile = AutomobileAd.ParseAutomobileAd(adContent, adAddress);
                Assert.IsNotNull(automobile);
            }
            else
            {
                if (!exceptionMessage.Contains("404"))
                {
                    Assert.Fail("Can't read address: " + adAddress);
                }
            }
        }
        private async Task <byte[]> GetSnapshotAsync()
        {
            var prefsInfo = new PrefsInfo(Prefs);

            if (prefsInfo.IsReady)
            {
                try
                {
                    var url = FormatUrl(UrlSnapshotFormat, prefsInfo.Host, prefsInfo.Port);
                    return(await HttpComm.Request()
                           .WithContentType(HttpContentType.Jpeg)
                           .WithMethod(HttpMethod.Get)
                           .WithUrl(url)
                           .GetResponseBytesAsync());
                }
                catch (Exception)
                {
                    return(null);
                }
            }
            return(null);
        }
        private async Task <PlayerExecutionData> GetVariablesAsync()
        {
            var prefsInfo = new PrefsInfo(Prefs);

            if (prefsInfo.IsReady)
            {
                try
                {
                    var url  = FormatUrl(UrlVariablesFormat, prefsInfo.Host, prefsInfo.Port);
                    var html = await HttpComm.Request()
                               .WithContentType(HttpContentType.Html)
                               .WithMethod(HttpMethod.Get)
                               .WithUrl(url)
                               .GetResponseStringAsync();

                    return(PlayerExecutionData.FromHtml(html));
                }
                catch (Exception)
                {
                    return(null);
                }
            }
            return(null);
        }
Esempio n. 10
0
 public void GetImgUrl()
 {
     _thread02 = new Thread(() =>
     {
         HttpComm httpComm = new HttpComm();
         // _driver = PhantomJSDriverComm.Driver;
         int count    = 0;
         int imgCount = 0;
         while (true)
         {
             if (_urls.TryDequeue(out var answer))
             {
                 var url = answer.Item1;
                 try
                 {
                     count++;
                     httpComm.Request(url);
                     var res  = new string(Encoding.UTF8.GetChars(httpComm.ResponseBts));
                     var imgs = res.GetAnswerDivRichContent();
                     for (int i = 0; i < imgs.Count; i++)
                     {
                         _ImgUrls.Enqueue(Tuple.Create(imgs[i], answer.Item2.Copy()));
                     }
                     imgCount += imgs.Count;
                     //_driver.Navigate().GoToUrl(url);
                     //Thread.Sleep(100);
                     ////if (_driver.Title.Contains("安全验证"))
                     ////{
                     ////    var captchaImg = _driver.FindElement(By.XPath("//button[@class='Button Unhuman-cofirm Button--primary Button--blue']"));
                     ////}
                     //var source = _driver.PageSource;
                     //var richContentInner = _driver.FindElement(By.XPath("//div[@class='RichContent RichContent--unescapable']"));
                     //var imgs = richContentInner.FindElements(By.XPath("//div[@class='VagueImage origin_image zh-lightbox-thumb']"));
                     //for (int i = 0; i < imgs.Count; i++)
                     //{
                     //    _ImgUrls.Enqueue(Tuple.Create(imgs[i].GetAttribute("data-src"), Data.Copy(answer.Item2)));
                     //}
                     //imgCount += imgs.Count;
                     Invoke(new MethodInvoker(delegate()
                     {
                         var message = string.Format("GetImgUrl:{0}({1})({2})({3})",
                                                     url,
                                                     count.ToString(),
                                                     imgs.Count,
                                                     imgCount);
                         rtb_getImgUrl.Text = message + "\r\n" + rtb_getImgUrl.Text;
                     }));
                 }
                 catch (Exception ex)
                 {
                     Invoke(new MethodInvoker(delegate()
                     {
                         rtb_errorMsg.Text = "GetImgUrl:" + ex.Message + "\r\n" + rtb_errorMsg.Text;
                     }));
                 }
             }
             else
             {
                 Invoke(new MethodInvoker(delegate()
                 {
                     rtb_getImgUrl.Text = "GetImgUrl:" + count.ToString() + "\r\n" + rtb_getImgUrl.Text;
                 }));
                 Thread.Sleep(1000);
             }
         }
     });
     _thread02.Start();
 }
Esempio n. 11
0
        public void DownImg()
        {
            _thread03 = new Thread(() =>
            {
                HttpComm httpComm = new HttpComm();
                int count         = 0;
                while (true)
                {
                    if (_ImgUrls.TryDequeue(out var img))
                    {
                        var url    = img.Item1;
                        var path01 = string.Format("{0}-{1}",
                                                   img.Item2.question.id,
                                                   img.Item2.question.title.ToDirectoryPath()
                                                   );
                        var path02 = string.Format("{0}-{1}-{2}",
                                                   img.Item2.id,
                                                   img.Item2.author.name.ToDirectoryPath(),
                                                   img.Item2.CreatedTime
                                                   );
                        var fullPath  = string.Empty;
                        var fileNname = string.Empty;
                        if (cb_isClassify.Checked)
                        {
                            fullPath  = Path.Combine(path01, path02);
                            fileNname = Guid.NewGuid().ToString() + Path.GetExtension(url);
                        }
                        else
                        {
                            fullPath  = path01;
                            fileNname = path02 + Guid.NewGuid().ToString() + Path.GetExtension(url);
                        }
                        if (!System.IO.Directory.Exists(fullPath))
                        {
                            Directory.CreateDirectory(fullPath);
                        }
                        var path = Path.Combine(fullPath, fileNname);

                        try
                        {
                            httpComm.Request(url);
                            var byts = httpComm.ResponseBts;

                            FileComm.WriteFile(path, byts);
                            Invoke(new MethodInvoker(delegate()
                            {
                                rtb_downImg.Text = "DownImg:" + url + "\r\n" + rtb_downImg.Text;
                            }));
                        }
                        catch (Exception ex)
                        {
                            Invoke(new MethodInvoker(delegate()
                            {
                                rtb_errorMsg.Text = "DownImg:" + ex.Message + "\r\n" + rtb_errorMsg.Text;
                            }));
                        }
                    }
                    else
                    {
                        Invoke(new MethodInvoker(delegate()
                        {
                            rtb_downImg.Text = "DownImg:" + (++count).ToString() + "\r\n" + rtb_downImg.Text;
                        }));
                        Thread.Sleep(1000);
                    }
                }
            });
            _thread03.Start();
        }
Esempio n. 12
0
 public TestPersonTests()
 {
     httpCommunication = new HttpComm();
 }
Esempio n. 13
0
        static void Main(string[] args)
        {
            var session_id = "user_session_id";
            var user_score = 999;
            var user_times = 74;

            Dictionary <string, string> header = new Dictionary <string, string>
            {
                { "charset", "utf-8" },
                { "Accept-Encoding", "gzip" },
                { "referer", " https://servicewechat.com/wx7c8d593b2c3a7703/5/page-frame.html" },
                { "content-type", "application/json" },
                { "User-Agent", "MicroMessenger/6.6.1.1220(0x26060133) NetType/WIFI Language/zh_CN" },
                { "Host", "mp.weixin.qq.com" }
            };
            var aes_key = session_id.Substring(0, 16);

            AESComm.CipherMode = System.Security.Cryptography.CipherMode.CBC;
            AESComm.Key        = aes_key;
            AESComm.IV         = aes_key;

            //其中game_data、musicList、touchList可以根据分数进行程序模拟生成
            var action_data = Newtonsoft.Json.JsonConvert.SerializeObject(
                new
            {
                score     = user_score,
                times     = user_times,
                game_data = Newtonsoft.Json.JsonConvert.SerializeObject(
                    new
                {
                    seed   = DateTime.Now.Ticks,
                    action = new object[][] {
                        new object[] { 0.8, 1.16, false },
                        new object[] { 0.592, 1.56, false },
                        new object[] { 0.816, 1.12, false },
                        new object[] { 0.852, 1.06, false },
                        new object[] { 0.512, 1.73, false },
                        new object[] { 0.626, 1.5, false },
                        new object[] { 0.101, 2.55, false },
                        new object[] { 0.083, 2.58, false },
                        new object[] { 0.8, 1.16, false },
                        new object[] { 0.592, 1.56, false },
                        new object[] { 0.816, 1.12, false },
                        new object[] { 0.852, 1.06, false },
                        new object[] { 0.512, 1.73, false },
                        new object[] { 0.626, 1.5, false },
                        new object[] { 0.101, 2.55, false },
                        new object[] { 0.083, 2.58, false }
                    },
                    musicList = new bool[] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false },
                    touchList = new object[][] {
                        new object[] { 105.88172, 571.77454 },
                        new object[] { 106.875, 572.5244 },
                        new object[] { 108.28125, 573.9697 },
                        new object[] { 110.390625, 575.95703 },
                        new object[] { 111.18164, 578.125 },
                        new object[] { 110.74219, 577.7637 },
                        new object[] { 114.87305, 585.35156 },
                        new object[] { 112.67578, 585.89355 },
                        new object[] { 105.88172, 571.77454 },
                        new object[] { 106.875, 572.5244 },
                        new object[] { 108.28125, 573.9697 },
                        new object[] { 110.390625, 575.95703 },
                        new object[] { 111.18164, 578.125 },
                        new object[] { 110.74219, 577.7637 },
                        new object[] { 114.87305, 585.35156 },
                        new object[] { 112.67578, 585.89355 }
                    },
                    version = "1"
                })
            });
            var encryptstr = AESComm.Encrypt(action_data);
            var pa         = "{\"base_req\":{\"session_id\":\""
                             + session_id + "\",\"fast\":1},\"action_data\":\""
                             + encryptstr + "\"}";
            var http = new HttpComm
            {
                Url     = "https://mp.weixin.qq.com/wxagame/wxagame_settlement",
                Method  = "post",
                Headers = header,
                Params  = pa
            };

            http.Request();
            var res = Encoding.UTF8.GetString(http.ResponseBts);

            Console.WriteLine(res);
            Console.ReadKey();
        }