Beispiel #1
0
        static void QueryIdCard(string url)
        {
            string requestParam = @"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:ASPSESSIONIDSQABCDRA=AJCBIMLAFHDDPOKGJDPBGIHB; gxskydzx31_f5ee_saltkey=V8j84g4P; gxskydzx31_f5ee_lastvisit=1503227237; gxskydzx31_f5ee_sid=wL5R7g; gxskydzx31_f5ee_lastact=1503230837%09nav_js.php%09; UM_distinctid=15dff8a57c50-0ad597d1229d24-474a0521-15f900-15dff8a57c61; Card3=Url=; ASPSESSIONIDQQCACCRB=PBHHKPLACDPLIPHOAFPIJOBI; CNZZDATA1259785388=339484251-1503230374-%7C1503230374
Host:idcard.gxsky.com
Referer:{url}
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36";

            requestParam = requestParam.Replace("{url}", url);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Headers.Add("Accept-Encoding", "gzip,deflate");
            //request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            request.Method    = "GET";
            request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0";
            request.KeepAlive = false;
            request.AllowWriteStreamBuffering = true;//对响应数据进行缓冲处理
            try
            {
                HttpWebResponse webResponse = null;
                Stream          str         = null;
                webResponse = (HttpWebResponse)request.GetResponse(); //此处有坑【如果http响应超时此处会抛出异常】
                if (webResponse.StatusCode != HttpStatusCode.OK)
                {                                                     //http请求失败
                }
                str = webResponse.GetResponseStream();
                GZipStream   gzip = new GZipStream(str, CompressionMode.Decompress);//解压缩
                Encoding     enc  = Encoding.GetEncoding("gb2312");
                StreamReader sr   = new StreamReader(gzip, enc);
                string       text = sr.ReadToEnd();
                str.Dispose();
                gzip.Close();
                sr.Close();
                // HttpClientExtend.GetHttpResponseData(url);
                AssemblyDataExt ass = new AssemblyDataExt();
                string          dir = ass.ForeachDir(ass.GetAssemblyDir(), 3);
                LoggerWriter.CreateLogFile(text, dir + "/" + ELogType.DataLog, ELogType.DataLog);
            }
            catch (Exception ex)
            {
                return;
            }
        }
Beispiel #2
0
        static void QueryUserRemarkLossId()
        {
            int cur = 1;

            string text = GetRequestData(string.Format(AppConfig.UserRemarkLoseIdCard, cur));

            string startRegex = "<form method=post";

            if (!text.Contains(startRegex))
            {
                return;
            }
            int             position = text.IndexOf(startRegex);
            string          page     = text.Substring(position + startRegex.Length);
            string          endRegex = "<input";
            string          releate  = page.Substring(0, page.IndexOf(endRegex));
            AssemblyDataExt ass      = new AssemblyDataExt();
            string          dir      = ass.ForeachDir(ass.GetAssemblyDir(), 3);

            LoggerWriter.CreateLogFile(text, dir + "/" + ELogType.DataLog, ELogType.DataLog);
            string sign = "#ff0000'>";

            releate = releate.Substring(releate.LastIndexOf(sign) + sign.Length);
            releate = releate.Substring(0, releate.LastIndexOf("</b>"));
            Regex           reg  = new Regex("([0-9]+)");
            MatchCollection list = reg.Matches(releate);
            //--->"3500</font></b>条记录 <b>35"
            Match total = list[0];// total
            Match limit = list[1];
            int   sum   = int.Parse(total.ToString());
            int   size  = int.Parse(limit.ToString());
            int   pages = (sum / size) + (sum % size > 0 ? 1 : 0);

            cur++;
            while (cur <= pages)
            {
                text = GetRequestData(string.Format(AppConfig.UserRemarkLoseIdCard, cur));
                cur++;
                if (string.IsNullOrEmpty(text))
                {
                    continue;
                }
                LoggerWriter.CreateLogFile(text, dir + "/" + ELogType.DataLog, ELogType.DataLog);
            }
        }