Exemple #1
0
    IEnumerator addRequestPOST(string nick, string language, string facebook, string apple, string google)
    {
        string   contentType      = "application/x-www-form-urlencoded";
        DateTime date             = DateTime.Today;
        int      timeInGame       = UnityEngine.Random.Range(1, 1000);
        int      numberOfSessions = UnityEngine.Random.Range(1, 500);
        int      sessionTime      = UnityEngine.Random.Range(1, 100);

        List <IMultipartFormSection> formData = new List <IMultipartFormSection>();

        formData.Add(new MultipartFormDataSection("from-whom", "game", contentType));
        formData.Add(new MultipartFormDataSection("nick", nick, contentType));
        formData.Add(new MultipartFormDataSection("date", date.ToString(), contentType));
        formData.Add(new MultipartFormDataSection("language", language, contentType));
        formData.Add(new MultipartFormDataSection("facebook", facebook, contentType));
        formData.Add(new MultipartFormDataSection("apple", apple, contentType));
        formData.Add(new MultipartFormDataSection("google", google, contentType));
        formData.Add(new MultipartFormDataSection("time-in-game", $"{timeInGame}", contentType));
        formData.Add(new MultipartFormDataSection("number-of-sessions", $"{numberOfSessions}", contentType));
        formData.Add(new MultipartFormDataSection("session-time", $"{sessionTime}", contentType));

        UnityWebRequest www = UnityWebRequest.Post(urlServer + "add/", formData);

        www.SetRequestHeader("X-CSRFToken", $"{token.csrf_token}");

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
        }
        else
        {
            accountId         = JsonUtility.FromJson <AccountId>(www.downloadHandler.text);
            accountId.isValid = www.isDone;

            Debug.Log("New ID: " + accountId.getId());

            loadMainScreen(accountId.getId(), state_nickname, state_language);
        }
    }