示例#1
0
        private bool parseNetProxyFromTianLu(List <CNetProxy> netProxyList, JArray netProxyItems)
        {
            foreach (JToken netProxyItem in netProxyItems)
            {
                CNetProxy netProxy = new CNetProxy();
                netProxy.Id          = netProxyItem ["id"].Value <string> ();
                netProxy.IpAddress   = netProxyItem ["ip"].Value <string> ();
                netProxy.Port        = netProxyItem ["port"].Value <int> ();
                netProxy.Description = netProxyItem ["area"].Value <string> ();
                netProxyList.Add(netProxy);
            }

            return(true);
        }
示例#2
0
 private void parseNetPrxyRecord(MySqlDataReader mySqlDataReader)
 {
     while (mySqlDataReader.Read())
     {
         CNetProxy netProxy = new CNetProxy();
         netProxy.Id          = mySqlDataReader["ID"].ToString();
         netProxy.Name        = mySqlDataReader["NAME"].ToString();
         netProxy.IpAddress   = mySqlDataReader["IP_ADDRESS"].ToString();
         netProxy.Port        = Convert.ToInt32(mySqlDataReader["PORT"]);
         netProxy.Description = mySqlDataReader["IP_ADDRESS"].ToString();
         netProxy.Status      = 1;
         _netProxyList.Add(netProxy);
     }
 }
示例#3
0
        public bool getNetProxyFromKuaiDaili(List <CNetProxy> netProxyTable, string orderId, int requestNumber)
        {
            DateTime getDateTime         = DateTime.Now;
            string   netProxyStr         = string.Format(netProxyProviderTemplate, orderId, requestNumber);
            string   netProxyListContent = CHttpRequest.GetWebRequest(netProxyStr, Encoding.UTF8);

            if (netProxyListContent == null)
            {
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, "Response is null.");
                return(false);
            }

            if (netProxyListContent.IndexOf("ERROR") >= 0)
            {
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, netProxyListContent);
                return(false);
            }

            string[] netProxyAddressList = netProxyListContent.Split('|');
            foreach (string netProxyAddress in netProxyAddressList)
            {
                if (netProxyAddress.Trim().Length == 0)
                {
                    continue;
                }

                _SystemLog.writeLog2Console(LOG_LEVEL.DEBUG, string.Format("proxy value <{0}>", netProxyAddress));
                string[]  stringValues = netProxyAddress.Split(':');
                CNetProxy netProxy     = new CNetProxy();
                netProxy.Id          = string.Format("{0}", Guid.NewGuid().ToString().ToUpper());
                netProxy.IpAddress   = stringValues[0];
                netProxy.Port        = Convert.ToInt32(stringValues[1]);
                netProxy.Description = string.Format("{0}", getDateTime);
                netProxy.Name        = string.Format("{0}:{1}", netProxy.IpAddress, netProxy.Port);
                netProxy.Status      = 1;
                netProxyTable.Add(netProxy);
            }

            if (batchSubmitNetProxyList(netProxyTable))
            {
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, "BATH SUBMIT SUCCESS");
            }
            else
            {
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, "BATH SUBMIT FAILD");
            }

            return(true);
        }
示例#4
0
        private static bool parseNetProxyList(JToken[] netProxyItems, List <CNetProxy> netProxyTable)
        {
            if (netProxyItems == null)
            {
                return(false);
            }

            foreach (JToken netProxyItem in netProxyItems)
            {
                CNetProxy netProxy = parseNetProxyItem(netProxyItem);
                if (netProxy != null)
                {
                    netProxyTable.Add(netProxy);
                }
            }

            return(true);
        }
示例#5
0
        private static CNetProxy parseNetProxyItem(JToken netPorxyItem)
        {
            CNetProxy netProxy = null;

            if (netPorxyItem == null)
            {
                return(null);
            }

            netProxy             = new CNetProxy();
            netProxy.Id          = netPorxyItem["ID"].Value <string>();
            netProxy.Name        = netPorxyItem["NAME"].Value <string>();
            netProxy.IpAddress   = netPorxyItem["IP_ADDRESS"].Value <string>();
            netProxy.Port        = netPorxyItem["PORT"].Value <int>();
            netProxy.Description = netPorxyItem["DESCRIPTION"].Value <string>();
            netProxy.Status      = netPorxyItem["STATUS"].Value <int>();

            return(netProxy);
        }
示例#6
0
        public static string getHtmlContent(string url, string charSet, CNetProxy netProxy, out string errorMessage)
        {
            errorMessage = "";
            string strWebData = string.Empty;

            try
            {
                WebClient webClient = new WebClient(); //创建WebClient实例
                webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36");
                webClient.Credentials = CredentialCache.DefaultCredentials;
                if (netProxy != null)
                {
                    webClient.Proxy = new WebProxy(netProxy.IpAddress, netProxy.Port);
                }
                byte[] myDataBuffer = webClient.DownloadData(url);
                strWebData = System.Text.Encoding.Default.GetString(myDataBuffer);
                //获取网页字符编码描述信息
                if (string.IsNullOrEmpty(charSet))
                {
                    Match  charSetMatch = Regex.Match(strWebData, "<meta([^>]*)charset=(\")?(.*)?\"", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                    string webCharSet   = charSetMatch.Groups[3].Value.Trim().ToLower();
                    if ((webCharSet != "gb2312") && (webCharSet != "gbk2312"))
                    {
                        webCharSet = "utf-8";
                    }

                    if (System.Text.Encoding.GetEncoding(webCharSet) != System.Text.Encoding.Default)
                    {
                        strWebData = System.Text.Encoding.GetEncoding(webCharSet).GetString(myDataBuffer);
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessage = string.Format("Get html content faild, error message<{0}>, netProxy<{1}>.", ex.Message, netProxy);
                return(null);
            }

            return(strWebData);
        }
示例#7
0
        public static string getHtmlContentUseCWebClicent(string url, Encoding ecoder, CNetProxy netProxy, out string errorMessage)
        {
            errorMessage = "";
            CWebClient webClient = null;

            try
            {
                webClient = new CWebClient(10000); //创建WebClient实例
                webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36");
                webClient.Credentials = CredentialCache.DefaultCredentials;
                if (netProxy != null)
                {
                    webClient.Proxy = new WebProxy(netProxy.IpAddress, netProxy.Port);
                }
                byte[] myDataBuffer = webClient.DownloadData(url);
                return(ecoder.GetString(myDataBuffer));
            }
            catch (Exception ex)
            {
                errorMessage = string.Format("Get page content faild,net proxy<{0}>, error message<{1}>.", netProxy, ex.Message);
                return(null);
            }
            finally
            {
                if (webClient != null)
                {
                    webClient.Dispose();
                    webClient = null;
                }
            }
        }