コード例 #1
0
    public void SendScoreDataToServer()
    {
        if (string.IsNullOrEmpty(context))
        {
            Debug.Log("Cannot send data to server. Property 'context' was null or empty");
            return;
        }
        if (string.IsNullOrEmpty(userName))
        {
            Debug.Log("Cannot send data to server. Property 'userName' was null or empty");
            return;
        }
        if (string.IsNullOrEmpty(scenario))
        {
            Debug.Log("Cannot send data to server. Property 'scenario' was null or empty");
            return;
        }
        var targetAddr = GeneratePutPointPathREST(context);
        var dto        = new UserScoreUpdateDTO
        {
            userName = userName,
            scenario = scenario,
            score    = score
        };

        Debug.Log(string.Format("Starting coroutine to PUT '{0}' with body '{1}'", targetAddr, dto.ToString()));
        StartCoroutine(SendScorePutRequest(dto, targetAddr));
    }
コード例 #2
0
    IEnumerator SendScorePutRequest(UserScoreUpdateDTO dto, string targetAddress)
    {
        byte[] rawData = System.Text.Encoding.UTF8.GetBytes(JsonUtility.ToJson(dto));
        using (var webRequest = UnityEngine.Networking.UnityWebRequest.Put(targetAddress, rawData))
        {
            webRequest.SetRequestHeader("Content-Type", "application/json");
            yield return(webRequest.SendWebRequest());

            if (webRequest.isNetworkError || webRequest.isHttpError)
            {
                Debug.Log(string.Format("Sending data FAILED: {0}", webRequest.error));
            }
            else
            {
                Debug.Log("Sending data SUCCEEDED");
            }
        }
    }