Exemple #1
0
        static async Task <string> Get(string gameType)
        {
            string url = "http://puzzle.win2012r2.oasis.dnnsharp.com/DesktopModules/DnnSharp/DnnApiEndpoint/Api.ashx?method=Highscore&GameType=" + gameType + "&datetime=" + DateTime.Now.ToString();

            try {
                //Create Client
                var client = new HttpClient();

                var uri = new Uri(url);

                //Call.Get response by Async
                var Response = await client.GetAsync(uri);

                //Result & Code
                Windows.Web.Http.HttpStatusCode statusCode = Response.StatusCode;

                //If Response is not Http 200
                //then EnsureSuccessStatusCode will throw an exception
                Response.EnsureSuccessStatusCode();

                return(await Response.Content.ReadAsStringAsync());
            } catch (Exception ex) {
                //...
                return("");
            }
        }
        public uint SetHttpValue(string path, object data, string key)
        {
            HttpRequestMessage request = null;

            if (data != null && key != null)
            {
                request = PrepareRequest(HttpMethod.Put, path, data, key);
            }
            else
            if (path.Equals(("system/receiveMode")))
            {
                request = PrepareLearnInMode(HttpMethod.Post, path, key);
            }
            else if (data != null && key == null)
            {
                request = PrepareAddDeviceRequest(HttpMethod.Post, path, data);
            }
            else if (data == null && key != null)
            {
                request = PrepareRemoveDeviceRequest(HttpMethod.Delete, path, data);
            }

            var response = httpClient.SendRequestAsync(request).AsTask().Result;

            Windows.Web.Http.HttpStatusCode statusCode = response.StatusCode;

            //Check for respsonse statuscode
            if (response.StatusCode == Windows.Web.Http.HttpStatusCode.InternalServerError)
            {
                return(500);
            }
            else if (response.StatusCode == Windows.Web.Http.HttpStatusCode.BadRequest)
            {
                return(400);
            }
            if (response.IsSuccessStatusCode)
            {
                return(0);
            }

            return(1);
        }