Exemplo n.º 1
0
        /// <summary>
        /// Sends a POST HTTP request
        /// </summary>
        public static void Post(string urlPath, string data, string authType, string authKey, Action <CallRequestContainer> callback, object request, object customData, bool isBlocking = false)
        {
            var requestContainer = new CallRequestContainer {
                RequestType = PlayFabSettings.RequestType, CallId = callIdGen++, AuthKey = authKey, AuthType = authType, Callback = callback, Data = data, Url = urlPath, Request = request, CustomData = customData
            };

            if (!isBlocking)
            {
#if PLAYFAB_IOS_PLUGIN
                PlayFabiOSPlugin.Post(PlayFabSettings.GetFullUrl(urlPath), PlayFabVersion.getVersionString(), requestContainer, PlayFabSettings.InvokeRequest);
#elif UNITY_WP8
                instance.StartCoroutine(instance.MakeRequestViaUnity(requestContainer));
#else
                if (PlayFabSettings.RequestType == WebRequestType.HttpWebRequest)
                {
                    lock (ActiveRequests)
                        ActiveRequests.Insert(0, requestContainer); // Parsing on this container is done backwards, so insert at 0 to make calls process in roughly queue order (but still not actually guaranteed)
                    PlayFabSettings.InvokeRequest(urlPath, requestContainer.CallId, request, customData);
                    _ActivateWorkerThread();
                }
                else
                {
                    instance.StartCoroutine(instance.MakeRequestViaUnity(requestContainer));
                }
#endif
            }
            else
            {
                StartHttpWebRequest(requestContainer);
                ProcessHttpWebResult(requestContainer, true);
                callback(requestContainer);
            }
        }
Exemplo n.º 2
0
        // This is the old Unity WWW class call.
        private IEnumerator MakeRequestViaUnity(CallRequestContainer requestContainer)
        {
            _pendingWwwMessages += 1;
            string fullUrl = PlayFabSettings.GetFullUrl(requestContainer.Url);

            byte[] bData = Encoding.UTF8.GetBytes(requestContainer.Data);

#if UNITY_4_4 || UNITY_4_3 || UNITY_4_2 || UNITY_4_2 || UNITY_4_0 || UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
            // Using hashtable for compatibility with Unity < 4.5
            Hashtable headers = new Hashtable();
#else
            Dictionary <string, string> headers = new Dictionary <string, string>();
#endif
            headers.Add("Content-Type", "application/json");
            if (requestContainer.AuthType != null)
            {
                headers.Add(requestContainer.AuthType, requestContainer.AuthKey);
            }
            headers.Add("X-ReportErrorAsSuccess", "true");
            headers.Add("X-PlayFabSDK", PlayFabVersion.getVersionString());
            WWW www = new WWW(fullUrl, bData, headers);

            PlayFabSettings.InvokeRequest(requestContainer.Url, requestContainer.CallId, requestContainer.Request, requestContainer.CustomData);

            yield return(www);

            requestContainer.ResultStr = null;
            requestContainer.Error     = null;
            if (!String.IsNullOrEmpty(www.error))
            {
                requestContainer.Error = GeneratePfError(HttpStatusCode.ServiceUnavailable, PlayFabErrorCode.ServiceUnavailable, www.error);
            }
            else
            {
                requestContainer.ResultStr = www.text;
            }

            requestContainer.InvokeCallback();

            _pendingWwwMessages -= 1;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sends a POST HTTP request
        /// </summary>
        public static void Post(string urlPath, string data, string authType, string authKey, Action <CallRequestContainer> callback, object request, object customData)
        {
            var requestContainer = new CallRequestContainer {
                RequestType = PlayFabSettings.RequestType, CallId = callIdGen++, AuthKey = authKey, AuthType = authType, Callback = callback, Data = data, Url = urlPath, Request = request, CustomData = customData
            };

#if PLAYFAB_WP8
            instance.StartCoroutine(instance.MakeRequestViaUnity(requestContainer));
#else
            if (PlayFabSettings.RequestType == WebRequestType.HttpWebRequest)
            {
                lock (ActiveRequests)
                    ActiveRequests.Insert(0, requestContainer);
                // Parsing on this container is done backwards, so insert at 0 to make calls process in roughly queue order (but still not actually guaranteed)
                PlayFabSettings.InvokeRequest(urlPath, requestContainer.CallId, request, customData);
                _ActivateWorkerThread();
            }
            else
            {
                instance.StartCoroutine(instance.MakeRequestViaUnity(requestContainer));
            }
#endif
        }