Ejemplo n.º 1
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;
        }