Ejemplo n.º 1
0
        public bool loadNetPorxyFromTianLuServer(List <CNetProxy> netProxyList)
        {
            //
            string errorMessage            = string.Empty;
            string httpRequestErrorMessage = string.Empty;
            string netProxyContent         = string.Empty;
            string serverUrl = @"http://office.tianluweiye.com:8008/service/proxies?speed=10000&num=30";

            netProxyContent = CHttpRequest.GetHttpWebRequest(serverUrl, out errorMessage);
            if (netProxyContent == null)
            {
                errorMessage = string.Format("Load from server<{0}>,error message<{1}> faild.", serverUrl, httpRequestErrorMessage);
                return(false);
            }

            string afterConvert = CPublic.unicode_js_GBK(netProxyContent);
            JArray items        = JArray.Parse(afterConvert);

            if ((items == null) || (items.Count == 0))
            {
                errorMessage = string.Format("Convert to JObject faild, content<{0}>.", afterConvert);
                return(false);
            }

            return(parseNetProxyFromTianLu(netProxyList, items));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public bool loadNetProxyFromServer(List <CNetProxy> netProxyTable, out string errorMessage)
        {
            string       httpRequestErrorMessage = string.Empty;
            string       netProxyContent         = string.Empty;
            string       serverUrl = _SystemConfig.getConfigItem("NetProxyManagementServiceUrl").ToString();
            UTF8Encoding encoder   = new UTF8Encoding();

            if ((serverUrl == null) || (serverUrl == string.Empty))
            {
                errorMessage = string.Format("Not config<{0}>, please check it.", "NetProxyManagementServiceUrl");
                return(false);
            }

            netProxyContent = CHttpRequest.getHttpWebRequest(serverUrl, "func=QUERY_NO_BASE64", encoder, out httpRequestErrorMessage);
            if (netProxyContent == null)
            {
                errorMessage = string.Format("Load from server<{0}>,error message<{1}> faild.", serverUrl, httpRequestErrorMessage);
                return(false);
            }

            string  afterConvert = CPublic.unicode_js_GBK(netProxyContent);
            JObject jobject      = JObject.Parse(afterConvert);

            if (jobject == null)
            {
                errorMessage = string.Format("Convert to JObject faild, content<{0}>.", afterConvert);
                return(false);
            }

            int errorCode = jobject["error_code"].Value <int>();

            if (errorCode != 0)
            {
                errorMessage = string.Format("Load net proxy data from server<{0}> faild, error code<{1}>,error message<{2}>.", serverUrl,
                                             errorCode,
                                             jobject["message"].Value <string>());
                return(false);
            }

            errorMessage = "";

            return(parseNetProxyList(jobject["data"].ToArray <JToken>(), netProxyTable));
        }
Ejemplo n.º 4
0
        public static string getHttpWebRequest(string url, string parameter, Encoding encoder, out string errorMessage)
        {
            byte[]         data       = null;
            Stream         newStream  = null;
            StreamReader   reader     = null;
            string         content    = null;
            HttpWebRequest webRequest = null;

            errorMessage = "";
            webRequest   = CHttpRequest.createHttpWebRequest(url, 30000, "POST");
            if (webRequest == null)
            {
                errorMessage = "create webrequest faild.";
                return(null);
            }

            UTF8Encoding encoding = new UTF8Encoding();

            try
            {
                data = encoding.GetBytes(parameter);
                webRequest.ContentLength = data.Length;
                newStream = webRequest.GetRequestStream();
                newStream.Write(data, 0, data.Length);
            }
            catch (Exception ex)
            {
                errorMessage = string.Format("Get request faild,error message<{0}>.", ex.Message);
                return(null);
            }
            finally
            {
                if (newStream != null)
                {
                    newStream.Close();
                    newStream.Dispose();
                    newStream = null;
                }
            }

            try
            {
                HttpWebResponse myResponse = (HttpWebResponse)webRequest.GetResponse();
                reader  = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
                content = reader.ReadToEnd();
                return(content.Replace("\ufeff", ""));
            }
            catch (Exception ex)
            {
                errorMessage = string.Format("Read response stream faild,url<{0}>, error message<{1}>.", url, ex.Message);
                return(null);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                    reader = null;
                }
            }
        }