Example #1
0
        //public const string STOREDOMAIN = "http://myplay.id/store_webview.php";

        public static IEnumerator SendPOST(ApiBridge apiBridge, ApiBridge.API api)
        {
            System.DateTime epochStart = new System.DateTime(2019, 11, 1, 0, 0, 0, System.DateTimeKind.Utc);
            int             curTime    = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;

            if (curTime - PlayerPrefs.GetInt(api.uri + "_time", 0) < api.cacheTime && PlayerPrefs.GetString(api.uri + "_value", "") != "")
            {
                PlayerPrefs.SetInt(api.uri + "_time", curTime);
                api.jsonReturn = PlayerPrefs.GetString(api.uri + "_value", "");
                apiBridge.GoodResponse(api);
            }
            else
            {
                WWWForm form = new WWWForm();
                if (api.jsonData.Length > 0)
                {
                    if (api.isDigested == 1)
                    {
                        string postid = (api.otp.Length == 0 ? Util.RandomChar(32) : api.otp);
                        form.AddField("post_id", postid.Trim());
                        form.AddField("post_time", System.DateTime.Now.ToString("yyMMdd-HHmmss").Trim());
                        api.jsonData = Digest.Write(api.jsonData, postid);
                    }
                    form.AddField("post_data", api.jsonData.Trim());
                }

                using (UnityWebRequest www = UnityWebRequest.Post(APIURI + api.uri, form))
                {
                    www.timeout         = 30;
                    www.chunkedTransfer = false;
                    yield return(www.SendWebRequest());

                    if (www.isNetworkError || www.isHttpError)
                    {
                        string[] tempError = ParseUnityError(www.error);
                        if (DEVELOPMENT)
                        {
                            tempError[0] = api.uri + " = " + www.error;
                        }
                        if (DEVELOPMENT)
                        {
                            Debug.Log(tempError[0]);
                        }
                        api.errorCode = (www.isNetworkError ? 500 : 501);
                        api.errorMsg  = new string[] { tempError[0], tempError[1] };
                        apiBridge.ParseError(api);
                    }
                    else
                    {
                        curTime = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;
                        PlayerPrefs.SetInt(api.uri + "_time", curTime);
                        PlayerPrefs.SetString(api.uri + "_value", www.downloadHandler.text);
                        api.jsonReturn = www.downloadHandler.text;
                        apiBridge.GoodResponse(api);
                    }
                }
            }
        }
Example #2
0
        public static IEnumerator ReadTempFile(ApiBridge apiBridge, ApiBridge.API api, string defaultNotFound = "")
        {
            using (UnityWebRequest www = UnityWebRequest.Get(CHATURI + api.uri))
            {
                www.timeout         = 30;
                www.chunkedTransfer = false;
                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    if (www.isHttpError && !www.isNetworkError)
                    {
                        api.jsonReturn = defaultNotFound;
                        apiBridge.GoodResponse(api);
                    }
                    else
                    {
                        string[] tempError = ParseUnityError(www.error);
                        if (DEVELOPMENT)
                        {
                            tempError[0] = api.uri + " = " + www.error;
                        }
                        if (DEVELOPMENT)
                        {
                            Debug.Log(tempError[0]);
                        }
                        api.errorCode = (www.isNetworkError ? 500 : 501);
                        api.errorMsg  = new string[] { tempError[0], tempError[1] };
                        apiBridge.ParseError(api);
                    }
                }
                else
                {
                    api.jsonReturn = www.downloadHandler.text;
                    apiBridge.GoodResponse(api);
                }
            }
        }