Esempio n. 1
0
        public IEnumerator RealWebRequest(string url, WWWForm lstformData, WebRequestTextEvent webRequestGetEvent)
        {
            UnityWebRequest webRequest = UnityWebRequest.Post(url, lstformData);

            httpRequestCount += 1;
            yield return(webRequest.SendWebRequest());

            if (webRequest.error == null || webRequest.error == "")
            {
                if (webRequestGetEvent != null)
                {
                    webRequestGetEvent.Invoke(webRequest.downloadHandler.text, DownStatus.Sucess, "");
                }
            }
            else
            {
                DownManager.Instance.DebugDownError(httpRequestCount, url, webRequest.error);
                if (httpRequestCount <= 3)
                {
                    DownManager.Instance.RegisterRequest(RealWebRequest(url, lstformData, webRequestGetEvent));
                }
                else
                {
                    if (webRequestGetEvent != null)
                    {
                        webRequestGetEvent.Invoke("", DownStatus.Fail, webRequest.error);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="webRequestGetEvent"></param>
        /// <param name="SavePath">如果为""则不需要保存</param>
        /// <param name="isReturnPath">默认是返回内容</param>
        /// <returns></returns>
        public IEnumerator RealWebRequest(string url, WebRequestTextEvent webRequestGetEvent, string SavePath = "", bool isReturnPath = false)
        {
            UnityWebRequest webRequest = UnityWebRequest.Get(url);

            httpRequestCount += 1;
            yield return(webRequest.SendWebRequest());

            if (webRequest.error == null || webRequest.error == "")
            {
                if (SavePath != null && SavePath != "")
                {
                    FileHelper.CreatFile(SavePath, webRequest.downloadHandler.data, true);
                }
                if (isReturnPath)
                {
                    if (webRequestGetEvent != null)
                    {
                        webRequestGetEvent.Invoke(SavePath, DownStatus.Sucess, "");
                    }
                }
                else
                {
                    if (webRequestGetEvent != null)
                    {
                        webRequestGetEvent.Invoke(webRequest.downloadHandler.text, DownStatus.Sucess, "");
                    }
                }
            }
            else
            {
                DownManager.Instance.DebugDownError(httpRequestCount, url, webRequest.error);
                if (httpRequestCount <= 3)
                {
                    DownManager.Instance.RegisterRequest(RealWebRequest(url, webRequestGetEvent, SavePath, isReturnPath));
                }
                else
                {
                    if (webRequestGetEvent != null)
                    {
                        webRequestGetEvent.Invoke("", DownStatus.Fail, webRequest.error);
                    }
                }
            }
        }