Esempio n. 1
0
        public static UpdateSoftEnt GetEnt(string url)
        {
            UpdateSoftEnt c = new UpdateSoftEnt();

            try
            {
                c.ProductVer = Program.ProductVer;
                IAASResponse reponse = IAASRequest.Reauest(url, RequestMethod.GET, "", "", "");
                if (reponse.StatusCode == HttpStatusCode.OK)
                {
                    if (reponse.Content.IndexOf("}") < 0)
                    {
                        reponse.Content = "{" + reponse.Content + "}";
                    }
                    if (reponse.Content.IndexOf("srb_ver_info_s") > 0)
                    {
                        c.ProductVer = reponse.Content.Substring(reponse.Content.IndexOf("srb_ver_info_s"), reponse.Content.IndexOf("srb_ver_info_e") - reponse.Content.IndexOf("srb_ver_info_s")).Replace("=", "").Replace("srb_ver_info_s", "");
                        c.DownUrl    = reponse.Content.Substring(reponse.Content.IndexOf("srb_down_info_s"), reponse.Content.IndexOf("srb_down_info_e") - reponse.Content.IndexOf("srb_down_info_s")).Replace("=", "").Replace("srb_down_info_s", "");
                    }
                    else
                    {
                        c = JsonToObj <UpdateSoftEnt>(reponse.Content);
                    }
                }
            }
            catch
            {
            }
            return(c);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static ProDictEntity GetProDict(string url, string key, List <UpdateDictEnt> pl = null)
        {
            ProDictEntity c = new ProDictEntity();


            try
            {
                c.DictList  = pl;
                c.HVID      = Program.HVID;
                c.SearchKey = key;
                RequestEntity r = new RequestEntity();
                r.OptCommand = OptCom.GetProDict.ToString();
                r.Content    = ToJson(c);
                r.Content    = Security.EncryptCommon(r.Content);
                IAASResponse reponse = IAASRequest.Reauest(url, RequestMethod.POST, "", "", ToJson(r));
                if (reponse.StatusCode == HttpStatusCode.OK)
                {
                    c = JsonToObj <ProDictEntity>(reponse.Content);
                }
            }
            catch
            {
                c.DictList = new List <UpdateDictEnt>();
            }
            return(c);
        }
Esempio n. 3
0
        public static InfoEntity GetMyInfo(string url)
        {
            InfoEntity c = new InfoEntity();

            c.LastMsgid = LastMsgid;
            try
            {
                c.HVID   = Program.HVID;
                c.ProVer = Program.ProductVer;
                RequestEntity r = new RequestEntity();
                r.OptCommand = OptCom.GetMyInfo.ToString();
                r.Content    = ToJson(c);
                r.Content    = Security.EncryptCommon(r.Content);
                IAASResponse reponse = IAASRequest.Reauest(url, RequestMethod.POST, "", "", ToJson(r));
                if (reponse.StatusCode == HttpStatusCode.OK)
                {
                    c         = JsonToObj <InfoEntity>(reponse.Content);
                    LastMsgid = c.LastMsgid;
                }
                else
                {
                    c.InfoStr = string.Empty;
                }
            }
            catch
            {
                c.InfoStr = string.Empty;
            }
            return(c);
        }
Esempio n. 4
0
        public static void EndDictUpdate(string url)
        {
            UpdateDictEnt c = new UpdateDictEnt();

            try
            {
                c.DictVersion = Win.WinInput.DictVersion;
                RequestEntity r = new RequestEntity();
                r.OptCommand = OptCom.EndUpdateDict.ToString();
                r.Content    = ToJson(c);
                r.Content    = Security.EncryptCommon(r.Content);
                IAASResponse reponse = IAASRequest.Reauest(url, RequestMethod.POST, "", "", ToJson(r));
                if (reponse.StatusCode == HttpStatusCode.OK)
                {
                    c = JsonToObj <UpdateDictEnt>(reponse.Content);
                }
            }
            catch
            {
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 获取dict更新地址
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static ColdDictEntity GetCloudDictUpdate(string url)
        {
            ColdDictEntity c = new ColdDictEntity();

            try
            {
                c.Pos = Win.WinInput.Input.ClouddDit.Count;
                RequestEntity r = new RequestEntity();
                r.OptCommand = OptCom.GetCloudDict.ToString();
                r.Content    = ToJson(c);
                r.Content    = Security.EncryptCommon(r.Content);
                IAASResponse reponse = IAASRequest.Reauest(url, RequestMethod.POST, "", "", ToJson(r));
                if (reponse.StatusCode == HttpStatusCode.OK)
                {
                    c = JsonToObj <ColdDictEntity>(reponse.Content);
                }
            }
            catch
            {
                c.NextHave = false;;
            }
            return(c);
        }
Esempio n. 6
0
        public static IAASResponse Request(

            string url, RequestMethod method, string user, string password,

            string sendData, int timeOut = 5000)
        {
            IAASResponse result;

            HttpWebRequest request;

            HttpWebResponse response = null;

            result = new IAASResponse();

            try
            {
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //加上这一句

                request = (HttpWebRequest)WebRequest.Create(url);

                request.Method = method.ToString();

                request.ContentType = "application/json";

                request.UserAgent = DefaultUserAgent;

                request.Proxy = SystemProxy;



                request.Credentials = new NetworkCredential(user, password);

                if (timeOut > 0)
                {
                    request.Timeout = timeOut;
                }

                AddHttpRequestParams(request, sendData, method);

                response = (HttpWebResponse)request.GetResponse();

                using (StreamReader reader = new StreamReader(

                           response.GetResponseStream(), System.Text.Encoding.UTF8))
                {
                    result.Content = reader.ReadToEnd();
                    result.Content = Security.DecryptCommon(result.Content.Substring(1, result.Content.Length - 2));
                    reader.Close();
                }

                switch (method)
                {
                case RequestMethod.GET:

                    result.Stauts = (response.StatusCode == HttpStatusCode.OK)

                            ? IAASResponseStatus.OK : IAASResponseStatus.Failed;

                    break;

                case RequestMethod.POST:

                    result.Stauts = (response.StatusCode == HttpStatusCode.OK ||

                                     response.StatusCode == HttpStatusCode.Created)

                            ? IAASResponseStatus.OK : IAASResponseStatus.Failed;

                    break;

                case RequestMethod.DELETE:

                    result.Stauts = (response.StatusCode == HttpStatusCode.OK)

                            ? IAASResponseStatus.OK : IAASResponseStatus.Failed;

                    break;

                case RequestMethod.PUT:

                    result.Stauts = (response.StatusCode == HttpStatusCode.OK ||

                                     response.StatusCode == HttpStatusCode.Created)

                            ? IAASResponseStatus.OK : IAASResponseStatus.Failed;

                    break;
                }
            }

            catch (System.Net.WebException e)
            {
                response = e.Response as HttpWebResponse;


                if (response != null)
                {
                    result.StatusCode = response.StatusCode;

                    try
                    {
                        using (StreamReader reader = new StreamReader(

                                   response.GetResponseStream(), System.Text.Encoding.UTF8))
                        {
                            result.Content = reader.ReadToEnd();

                            reader.Close();
                        }
                    }
                    catch
                    {
                        result.Content = null;
                    }
                }

                result.Stauts = IAASResponseStatus.Exception;

                if (string.IsNullOrEmpty(result.Content))
                {
                    result.Content = string.Format(

                        "{0}\r\n{1}", e.Message, e.StackTrace);
                }
            }
            catch (Exception e)
            {
                result.Stauts  = IAASResponseStatus.Exception;
                result.Content = string.Format(

                    "{0}\r\n{1}", e.Message, e.StackTrace);
            }

            finally
            {
                if (response != null)
                {
                    result.StatusCode = response.StatusCode;
                }

                result.InputTxt = sendData;

                result.RequestUrl = url;
            }

            return(result);
        }