예제 #1
0
    private IEnumerator WaitForServerResponse(APIRequests request)
    {
        if (!IsInternetAvailable())
        {
            if (request.isShowErrorMessage)
            {
                request.callbackMethod(request.requestCode, "", request.isShowErrorMessage, "Internet Connection not available.");
            }

            yield break;
        }

        request.timerMethod = WaitForAPIResponse(request);
        Dictionary <string, string> headers = new Dictionary <string, string>();

        headers.Add("Content-Type", "application/json");
        //Debug.LogError(request.url);
        WWW www = new WWW(request.url, request.pdata, headers);

        StartCoroutine(request.timerMethod);

        yield return(www);

        StopCoroutine(request.timerMethod);

#if DEBUG_LOG
        Debug.Log("Response Found requestCode = " + request.requestCode + "    data = " + www.text);
#endif


        if (request.callbackMethod != null)
        {
            string errorMessage = "";

            if (www.error != null)
            {
                errorMessage = www.error;
            }
            else if (string.IsNullOrEmpty(www.text))
            {
                errorMessage = "Server response not found, please check your internet connection is working properly";
            }
            //Debug.Log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   " + www.text);
            request.callbackMethod(request.requestCode, www.text, request.isShowErrorMessage, errorMessage);
        }

        www.Dispose();
        www = null;
    }
예제 #2
0
    private void SendRequestToServer(APIRequests request)
    {
        if (request.retryCount >= GameConstants.API_RETRY_LIMIT)
        {
            Debug.Log("API retry count exceeded api code = " + request.requestCode);

            if (request.callbackMethod != null)
            {
                request.callbackMethod(request.requestCode, "", request.isShowErrorMessage, "Retry count exceeded.");
            }
            else
            {
                Debug.LogError("Call back method is null ");
            }
            return;
        }

        ++request.retryCount;
        request.requestMethod = WaitForServerResponse(request);
        StartCoroutine(request.requestMethod);
    }