IEnumerator GetLogin(string URL, string auth, Action <string> callback)
    {
        using (UnityWebRequest www = UnityWebRequest.Get(URL)) {
            UnityWebRequest.ClearCookieCache();
            www.SetRequestHeader("Content-Type", "application/json");
            www.SetRequestHeader("AUTHORIZATION", auth);
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else if (www.isHttpError)
            {
                Debug.Log(www.error);
                warningMessage.enabled = true;
            }
            else
            {
                Debug.Log("Login successful!");
                warningMessage.enabled = false;
                string[] aux = www.GetResponseHeader("Set-Cookie").Split(';');
                callback?.Invoke(aux[0]);
            }
        }
    }
Exemplo n.º 2
0
        public static async Task RequestPost(string endpoint, string formData, UnityAction <int, string> _callback, bool token)
        {
            UnityWebRequest request = UnityWebRequest.Post(host + api + endpoint, formData);

            Debug.Log(formData);
            Debug.Log(request.url);
            UnityWebRequest.ClearCookieCache();
            if (token)
            {
                request.SetRequestHeader("Token", AppManager.Instance.userInfo.access_token);
            }
            request.SetRequestHeader("Content-Type", "application/json");
            if (formData.Length > 0)
            {
                byte[] bodyRaw       = System.Text.Encoding.UTF8.GetBytes(formData);
                var    uploadHandler = new UploadHandlerRaw(bodyRaw);
                request.uploadHandler = uploadHandler;
            }
            request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
            await request.SendWebRequest();

            Debug.Log("HTTP CODE: " + request.responseCode);
            Debug.Log("SERVER RESPONDED: " + request.downloadHandler.text);
            if (request.responseCode == 200)
            {
                _callback?.Invoke((int)request.responseCode, request.downloadHandler.text);
            }
            else if (request.isNetworkError || request.isHttpError)
            {
                //ApplicationManager.instance.ErrorScreen.GetComponent<ErrorScreen>().error.text = "Отсутствует соединение с интернетом, проверьте подключение";
                //ApplicationManager.instance.ErrorScreen.SetActive(true);
            }
        }
Exemplo n.º 3
0
    public void firstLocalization(float langitude, float latitude, string path, Action <StickerInfo[]> getStickers)
    {
        UnityWebRequest.ClearCookieCache();
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
        if (getStickers != null)
        {
            getStickersAction = getStickers;
        }
        string framePath;

        if (!editorTestMode)
        {
            framePath = CamGetFrame();
            Debug.Log("framePath =" + framePath);
        }
        else
        {
            framePath = path;
        }
        cameraRotationInLocalization = ARCamera.transform.rotation.eulerAngles;
        cameraPositionInLocalization = ARCamera.transform.position;
        if (framePath != null)
        {
            uploadFrame(framePath, apiURL, langitude, latitude, camLocalize);
        }
    }
Exemplo n.º 4
0
    private void ForceToLoginView(bool isShowSwitch = false)
    {
        //这下面的执行顺序不要轻易修改
        UnityWebRequest.ClearCookieCache();
        SdkHelper.AccountAgent.IsLogin = false;
        _backBtn.Hide();
        ClientData.CustomerSelectedLevel        = null;
        ClientData.CustomerSelectedCapsuleLevel = null;
        GuideManager.Reset();
        ClientTimer.Instance.Cleanup();
        NetWorkManager.CookieStr = null;
        NetWorkManager.InitHead();
        ModuleManager.Instance.DestroyAllModule();
        GlobalData.InitData();
        PopupManager.CloseAllWindow();
        SdkHelper.CustomServiceAgent.Reset();
        LoadingProgress.Instance.Show();

        if (isShowSwitch)
        {
            ModuleManager.Instance.EnterModule(ModuleConfig.MODULE_UPDATE, false, true, LoginCallbackType.Switch);
        }
        else
        {
            ModuleManager.Instance.EnterModule(ModuleConfig.MODULE_UPDATE);
        }
    }
Exemplo n.º 5
0
        /// <summary>
        /// Sends get request
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="_callback"></param>
        /// <param name="token"></param>
        /// <param name="addetive"></param>
        /// <returns></returns>

        public static async Task RequestGet(string endpoint, UnityAction <int, string> _callback = null, bool token = true, string addetive = null)
        {
            string requestString = host + api + endpoint + addetive;

            Debug.Log(requestString);
            UnityWebRequest request = UnityWebRequest.Get(host + api + endpoint + addetive);

            UnityWebRequest.ClearCookieCache();
            if (token)
            {
                request.SetRequestHeader("Token", AppManager.Instance.userInfo.access_token);
            }
            request.SetRequestHeader("Content-Type", "application/json");
            await request.SendWebRequest();

            Debug.Log("HTTP CODE: " + request.responseCode);
            Debug.Log("SERVER RESPONDED: " + request.downloadHandler.text);
            if (request.responseCode == 200)
            {
                _callback?.Invoke((int)request.responseCode, request.downloadHandler.text);
            }
            else if (request.isNetworkError || request.isHttpError)
            {
                //ApplicationManager.instance.ErrorScreen.GetComponent<ErrorScreen>().error.text = "Отсутствует соединение с интернетом, проверьте подключение";
                //ApplicationManager.instance.ErrorScreen.SetActive(true);
            }
        }
Exemplo n.º 6
0
    //Check if the given username and credentials match an existing user
    //When called, sets to the AWAITING_RESPONSE state
    //Once a response is received, changes to RESPONSE_RECEIVED
    //Sets response based on
    // 200 - SUCCESS (credentials are valid)
    // 404 - NOTFOUND (credentials not valid)
    // ?   - OTHER (something else)
    IEnumerator CheckUserCredentials(string username, string password)
    {
        UnityWebRequest.ClearCookieCache();
        Debug.Log("Checking user credentials are valid");

        if (currentState != DbConnectionState.READY)
        {
            Debug.LogWarning("Tried to connect to the DB before receiving response, will not process this request");
            yield break;
        }

        currentState = DbConnectionState.AWAITING_RESPONSE;
        yield return(StartCoroutine(CheckDbConnection()));

        if (currentState != DbConnectionState.AWAITING_RESPONSE)
        {
            yield break;
        }

        WWWForm form = new WWWForm();

        form.AddField("username", username);
        form.AddField("password", password);

        using (UnityWebRequest www = UnityWebRequest.Post(baseURL + "check_user.php", form)) {
            yield return(www.SendWebRequest());

            DbResponseState state;

            if (www.responseCode == 200)
            {
                state = DbResponseState.SUCCESS;
            }
            else if (www.responseCode == 404)
            {
                state = DbResponseState.NOTFOUND;
            }
            else
            {
                Debug.LogError("Unexpected response when checking user credentials: " + www.error);
                Debug.Log(www.downloadHandler.text);
                state = DbResponseState.OTHER;
            }

            if (disregardNext)
            {
                currentState = DbConnectionState.READY;
                lastResponse = null;
            }
            else
            {
                currentState = DbConnectionState.RESPONSE_RECEIVED;
                lastResponse = new DbResponse(state, www.downloadHandler.text, www.GetResponseHeaders());
            }
        }
    }
Exemplo n.º 7
0
    //Save the values of the data recorder to the DB.
    //When called, sets to the AWAITING_RESPONSE state
    //Once a response is received, changes to RESPONSE_RECEIVED
    //Sets response based on
    // 200 - SUCCESS (scores saved)
    // 404 - NOTFOUND (scores not saved)
    // ?   - OTHER (something else)
    IEnumerator SaveData(DataRecorder recorder)
    {
        UnityWebRequest.ClearCookieCache();

        if (currentState != DbConnectionState.READY)
        {
            Debug.LogWarning("Tried to connect to the DB before receiving response, will not process this request");
            yield break;
        }

        currentState = DbConnectionState.AWAITING_RESPONSE;
        yield return(StartCoroutine(CheckDbConnection()));

        if (currentState != DbConnectionState.AWAITING_RESPONSE)
        {
            yield break;
        }

        var www = new UnityWebRequest(baseURL + "save_data.php", "POST");

        byte[] bodyRaw = Encoding.UTF8.GetBytes(recorder.ToJSON());
        www.uploadHandler   = (UploadHandler) new UploadHandlerRaw(bodyRaw);
        www.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
        www.SetRequestHeader("Content-Type", "application/json");

        yield return(www.SendWebRequest());

        DbResponseState state;

        if (www.responseCode == 200)
        {
            state = DbResponseState.SUCCESS;
        }
        else if (www.responseCode == 404)
        {
            state = DbResponseState.NOTFOUND;
        }
        else
        {
            Debug.LogError("Unexpected response when trying to save data: " + www.error);
            Debug.Log(www.downloadHandler.text);
            state = DbResponseState.OTHER;
        }

        if (disregardNext)
        {
            currentState = DbConnectionState.READY;
            lastResponse = null;
        }
        else
        {
            currentState = DbConnectionState.RESPONSE_RECEIVED;
            lastResponse = new DbResponse(state, www.downloadHandler.text, www.GetResponseHeaders());
        }
    }
Exemplo n.º 8
0
        internal static UnityWebRequest initRequest(
            string url,
            string method)
        {
            var request = new UnityWebRequest(url, method);

            request.downloadHandler = new DownloadHandlerBuffer();
            request.SetRequestHeader("X-Requested-With", "XmlHttpRequest");
            UnityWebRequest.ClearCookieCache();
            request.SetRequestHeader(COOKIE, _cookieHeader());
            return(request);
        }
Exemplo n.º 9
0
        static UnityWebRequest initRequest(
            string url,
            string method)
        {
            var request = new UnityWebRequest {
                url             = url,
                method          = method,
                downloadHandler = new DownloadHandlerBuffer()
            };

            request.SetRequestHeader("X-Requested-With", "XmlHttpRequest");
            UnityWebRequest.ClearCookieCache();
            request.SetRequestHeader(COOKIE, _cookieHeader());
            request.SetRequestHeader("AppVersion", Config.versionNumber);
            return(request);
        }
Exemplo n.º 10
0
        public static void CheckServerTime(Action <bool> pOnFinished)
        {
            if (mCheckingTime)
            {
                return;
            }

            string url = "https://showcase.api.linx.twenty57.net/UnixTime/tounix?date=now";

            //var form = new WWWForm();
            UnityWebRequest.ClearCookieCache();
            var request = UnityWebRequest.Get(url);

            request.SendWebRequest();

            mCheckingTime = true;
            WaitUtil.Start(() => request.isDone, () =>
            {
                mCheckingTime = false;
                if (request.isNetworkError)
                {
                    pOnFinished.Raise(false);
                }
                else
                {
                    if (request.responseCode == 200)
                    {
                        var text      = request.downloadHandler.text;
                        long unixTime = 0;
                        if (long.TryParse(text, out unixTime))
                        {
                            mStartServerTime = Config.UnixTimeStampToDateTime(unixTime);
                        }
                        mAppTimeWhenGetServerTime = Time.unscaledTime;
                        pOnFinished.Raise(true);
                    }
                    else
                    {
                        pOnFinished.Raise(false);
                    }
                }
            });
        }
Exemplo n.º 11
0
    void Start()
    {
        string ver = Application.version;

        if (PlayerPrefs.HasKey("bver"))
        {
            if (!(PlayerPrefs.GetString("bver").Equals(ver)))
            {
                UnityWebRequest.ClearCookieCache();
                Caching.ClearCache();
                PlayerPrefs.DeleteAll();
                PlayerPrefs.SetString("bver", ver);
            }
        }
        else
        {
            UnityWebRequest.ClearCookieCache();
            Caching.ClearCache();
            PlayerPrefs.DeleteAll();
            PlayerPrefs.SetString("bver", ver);
        }

        Debug.Log("Version " + Application.version + " bver " + ver);

        gph = GetComponent <GetPlaceHoldersDev>();
        stickerInfoForPanel = null;
        stickerDeActivate   = null;
        gloc = 0; bloc = 0;

        if (PlayerPrefs.HasKey("TimeForRelocation"))
        {
            float val = PlayerPrefs.GetFloat("TimeForRelocation");
            gph.setTimeForRelocation(val);
            placeholderRelocationTimer.text = "" + val;
        }
        else
        {
            PlayerPrefs.SetFloat("TimeForRelocation", gph.timeForRelocation);
        }

        aRcamera = Camera.main.gameObject;
    }
Exemplo n.º 12
0
        private static IEnumerator waitForRequest(UnityWebRequest www, Request request, FinishCallback callback)
        {
            using (www) {
                yield return(www.SendWebRequest());

                if (string.IsNullOrEmpty(www.error))
                {
                    Dictionary <string, string> headers = new Dictionary <string, string>(www.GetResponseHeaders());
                    if (request.Cookies != null)
                    {
                        request.Cookies.Update(headers);
                    }
                    int code = (int)www.responseCode;
                    UnityWebRequest.ClearCookieCache();
                    callback(new Response(www.downloadHandler.text, code, StatusCodes.MessageFromCode(code), headers, request.Cookies));
                }
                else
                {
                    callback(Response.BuildError(www.error));
                }
            }
        }
Exemplo n.º 13
0
        IEnumerator Start()
        {
            realm = "";
            nonce = "";
            qop   = "";

            if (camCoderIPAddress == null || camCoderIPAddress == "")
            {
                yield break;
            }

            entryPoint = "/api.php";
            UnityWebRequest getRequest = UnityWebRequest.Get("http://" + camCoderIPAddress + entryPoint);

            UnityWebRequest.ClearCookieCache();
            yield return(getRequest.Send());

            if (getRequest.isNetworkError)
            {
                Debug.Log(getRequest.error);
            }
            else
            {
                if (getRequest.responseCode == 200)
                {
                    var resps = getRequest.GetResponseHeaders();
                    foreach (KeyValuePair <string, string> kvp in resps)
                    {
                        Debug.Log(kvp.Value);
                    }
                }
                else if (getRequest.responseCode == 401)
                {
                    var resps = getRequest.GetResponseHeaders();
                    foreach (KeyValuePair <string, string> kvp in resps)
                    {
                        if (kvp.Key == "WWW-Authenticate")
                        {
                            UnityWebRequest authRequest =
                                UnityWebRequest.Get("http://" + camCoderIPAddress + entryPoint);

                            var vals = kvp.Value.Replace("\"", "").Split(',');
                            foreach (var val in vals)
                            {
                                var tmps = val.Split('=');
                                if (tmps[0].Contains("realm"))
                                {
                                    realm = tmps[1];
                                }
                                else if (tmps[0].Contains("nonce"))
                                {
                                    nonce = tmps[1];
                                }
                                else if (tmps[0].Contains("qop"))
                                {
                                    qop = tmps[1];
                                }
                            }

                            cnonce          = "cnonce";
                            wwwAuthenticate = kvp.Value;
                            authValue       = BuildAuthrizeHeader("GET", entryPoint);
                            authRequest.SetRequestHeader("Authorization", authValue);
                            yield return(authRequest.Send());

                            if (authRequest.responseCode == 200)
                            {
                                var respHeads = authRequest.GetResponseHeaders();
                                foreach (KeyValuePair <string, string> header in respHeads)
                                {
                                    var elements = header.Value.Split(',');
                                    foreach (var element in elements)
                                    {
                                        if (element.Contains("SessionID"))
                                        {
                                            sessionID = element.Split('=')[1];
                                            break;
                                        }
                                    }
                                }

                                if (sessionID != "")
                                {
                                    entryPoint            = "/cgi-bin/api.cgi";
                                    isAuthenticateSuccess = true;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
 [Button(ButtonSizes.Medium), GUIColor("AlarmColor"), BoxGroup("Settings"), HorizontalGroup("Settings/1")] public void ClearCookieCache() => UnityWebRequest.ClearCookieCache();
Exemplo n.º 15
0
    public override void Init()
    {
        var data = string.Empty;

        if (Application.platform == RuntimePlatform.Android)
        {
            //LogUtils.Log("loading launch cfg at android... path =", CFG_PATH);

            var url = new System.Uri(CFG_PATH.DataPath());
            UnityWebRequest.ClearCookieCache();
            UnityWebRequest reader = UnityWebRequest.Get(url);
            reader.SendWebRequest();

            while (!reader.isDone)
            {
                //.Log("loading launch cfg...");
            }

            data = reader.downloadHandler.text;

            //LogUtils.Log("loading launch cfg at android... data =", data);

            //JsonData jsond = JsonMapper.ToObject(File.ReadAllText(API_PATH));
            //if(jsond.Count > 0 && jsond[0].Count > 0)
            //{
            //    Config.APPID = Convert.ToInt32(jsond[0]["appid"]);
            //    Debug.Log(Config.APPID);
            //}
        }
        else
        {
            var file = new FileInfo(CFG_PATH.DataPath());
            if (file.Exists)
            {
                var fs = file.OpenText();
                data = fs.ReadToEnd();
                fs.Close();
            }
        }

        if (!string.IsNullOrEmpty(data))
        {
            //LogUtils.Log(data);
            Config = JsonMapper.ToObject <LaunchConfig>(data);
        }
        else
        {
            //LogUtils.Log("load launch cfg failed...");
            Config = new LaunchConfig();
        }


        if (Application.platform == RuntimePlatform.Android)
        {
            //LogUtils.Log("loading launch cfg at android... path =", API_PATH);

            var url = new System.Uri(API_PATH.DataPath());
            UnityWebRequest.ClearCookieCache();
            UnityWebRequest reader = UnityWebRequest.Get(url);
            reader.SendWebRequest();

            while (!reader.isDone)
            {
                //LogUtils.Log("loading launch cfg...");
            }

            data = reader.downloadHandler.text;

            //LogUtils.Log("loading launch cfg at android... data =", data);
        }
        else
        {
            var file = new FileInfo(API_PATH.DataPath());
            if (file.Exists)
            {
                var fs = file.OpenText();
                data = fs.ReadToEnd();
                fs.Close();
            }
        }

        if (!string.IsNullOrEmpty(data))
        {
#if BRANCH_TAPTAP
            Config.APPID = 12;
            Debug.Log("Config.APPID = " + Config.APPID);
#else
            //LogUtils.Log(data);
            JsonData deJson = LitJson.JsonMapper.ToObject(data);
            if (deJson.Keys.Contains("appid"))
            {
                Config.APPID = int.Parse(deJson["appid"].ToString());
                //Debug.Log("Config.APPID = " + Config.APPID);
            }
            if (deJson.Keys.Contains("zoneid"))
            {
                Config.ZONEID = int.Parse(deJson["zoneid"].ToString());
                //Debug.Log("Config.APPID = " + Config.ZONEID);
            }
#endif
        }
        else
        {
            //LogUtils.Log("load launch appid failed...");
        }
    }
Exemplo n.º 16
0
 public void ClearCash()
 {
     UnityWebRequest.ClearCookieCache();
     Caching.ClearCache();
 }
 public void ClearCookies(Uri uri)
 {
     UnityWebRequest.ClearCookieCache(uri);
 }
Exemplo n.º 18
0
 void Start()
 {
     UnityWebRequest.ClearCookieCache();
     OnRefreshBtnClick();
 }