public static void LogTutorialStatusUpdate(string lessonId, string lessonStatus)
        {
            var userId = UnityConnectProxy.GetUserId();

            if (userId.IsNullOrEmpty())
            {
                return;
            }
            var getLink = @"/v1/users/" + userId + @"/lessons";
            var address = HostAddress + getLink;

            var jsonData = RegisterLessonRequest.GetJSONString(lessonStatus, userId, lessonId);
            var req      = UnityWebRequest.Post(address, jsonData);
            var data     = System.Text.Encoding.UTF8.GetBytes(jsonData);

            req.uploadHandler = new UploadHandlerRaw(data);

            req.SetRequestHeader("Content-Type", "application/json");
            req.SetRequestHeader("X-IET-Version", GetVersion());
            req.SetRequestHeader("Authorization", "Bearer " + UnityConnectProxy.GetAccessToken());

            SendWebRequest(req, r =>
            {
                if (!IsRequestSuccess(r))
                {
                    return;
                }
            });
        }
示例#2
0
        public static async void LogTutorialStatusUpdate(string lessonId, string lessonStatus)
        {
            var userId = UnityConnectProxy.GetUserId();

            if (userId.IsNullOrEmpty())
            {
                return;
            }
            var getLink = @"/v1/users/" + userId + @"/lessons";

            var jsonData = RegisterLessonRequest.GetJSONString(lessonStatus, userId, lessonId);

            // UnityWebRequests were causing memory leaks here, so they were replaced with HttpClient
            using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, getLink))
            {
                var data = new StringContent(jsonData, Encoding.UTF8, "application/json");

                request.Content = data;

                request.Headers.Add("X-IET-Version", GetVersion());
                request.Headers.Add("Authorization", "Bearer " + UnityConnectProxy.GetAccessToken());
                HttpResponseMessage response = await s_HttpClient.SendAsync(request);
            }
        }