コード例 #1
0
        public async Task <List <T> > GetALLUser <T>(string URL)
        {
            if (NetworkCheck.IsInternet())
            {
                try
                {
                    HttpClient client = new HttpClient();
                    client.MaxResponseContentBufferSize = 256000;
                    HttpResponseMessage res = await client.GetAsync(URL);

                    if (res.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        var jsonString = await res.Content.ReadAsStringAsync();

                        List <T> qls = new List <T>();
                        if (jsonString != "")
                        {
                            //Converting JSON Array Objects into generic list
                            qls = JsonConvert.DeserializeObject <List <T> >(jsonString);
                            return(qls);
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(default(List <T>));
        }
コード例 #2
0
        public async Task PostQuestion(string URL, Question question_post)
        {
            if (NetworkCheck.IsInternet())
            {
                try
                {
                    HttpClient client = new HttpClient();
                    var        json   = JsonConvert.SerializeObject(question_post);

                    HttpContent content = new StringContent(json);

                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    HttpResponseMessage res = await client.PostAsync(URL, content);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
コード例 #3
0
        public async Task <T> CheckDevice <T>(string URL)
        {
            if (NetworkCheck.IsInternet())
            {
                try
                {
                    HttpClient client = new HttpClient();
                    client.MaxResponseContentBufferSize = 256000;
                    string res = await client.GetStringAsync(URL);

                    if (res != "")
                    {
                        List <T> uls = JsonConvert.DeserializeObject <List <T> >(res);
                        return(uls[0]);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(default(T));
        }
コード例 #4
0
        public async Task <T> UpdateUser <T>(string URL, User user_put)
        {
            if (NetworkCheck.IsInternet())
            {
                try
                {
                    HttpClient client = new HttpClient();
                    client.MaxResponseContentBufferSize = 256000;

                    var json = JsonConvert.SerializeObject(user_put);

                    HttpContent content = new StringContent(json);

                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    HttpResponseMessage res = await client.PutAsync(URL, content);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(default(T));
        }