Beispiel #1
0
        private void requestThread()
        {
            HttpWebResponse httpWebRespones = null;

            try
            {
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                HttpWebRequest httpWebRequest = WebRequest.Create(githubUrl) as HttpWebRequest;
                httpWebRequest.Timeout           = 60 * 1000;
                httpWebRequest.ReadWriteTimeout  = 60000;
                httpWebRequest.AllowAutoRedirect = true;
                httpWebRequest.UserAgent         = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36";
                httpWebRespones = (HttpWebResponse)httpWebRequest.GetResponse();


                using (Stream stream = httpWebRespones.GetResponseStream())
                {
                    List <byte> lst   = new List <byte>();
                    int         nRead = 0;
                    while ((nRead = stream.ReadByte()) != -1)
                    {
                        lst.Add((byte)nRead);
                    }
                    byte[] bodyBytes = lst.ToArray();

                    string body = Encoding.UTF8.GetString(bodyBytes, 0, bodyBytes.Length);

                    var data = JsonConvert.DeserializeObject <GithubModel>(body);
                    Info.IsPre       = data.prerelease;
                    Info.Title       = data.name;
                    Info.Version     = data.tag_name;
                    Info.DownloadUrl = data.assets[0].browser_download_url;
                    Info.HtmlUrl     = data.html_url;
                    RequestCompleteEvent?.Invoke(this, Info);
                }
            }
            catch (Exception ec)
            {
                LogHelper.Warning(ec.ToString());
                RequestErrorEvent?.Invoke(this, ec.Message);
            }
        }
Beispiel #2
0
    private void OnRequestErrorHandle(BaseEvent e)
    {
        RequestErrorEvent evt = e as RequestErrorEvent;

        if (evt.type == RequestErrorEvent.Type.AnalysisError)
        {
            if (GameMainManager.instance.uiManager != null)
            {
                Alert.Show("数据解析错误");
                Waiting.Disable();
            }
        }
        else if (evt.type == RequestErrorEvent.Type.TimeOut)
        {
            Debug.Log(string.Format("请求失败:{0} 正在尝试重新请求", evt.request.State.ToString()));
            if (GameMainManager.instance.uiManager != null)
            {
                GameMainManager.instance.uiManager.isWaiting = false;
                Alert.Show("连接失败:" + evt.request.State.ToString(), Alert.OK | Alert.CANCEL, (isOK) => {
                    if (isOK == Alert.OK)
                    {
                        HttpProxy.SendRequest(evt.request);
                    }
                }, "重试");

                Waiting.Disable();
            }
            else
            {
                HttpProxy.SendRequest(evt.request);
            }
        }
        else
        {
            if (GameMainManager.instance.uiManager != null)
            {
                Debug.Log(string.Format("请求失败:{0} |{1}", evt.type.ToString(), evt.request.Uri));
                Waiting.Disable();
            }
        }
    }