Esempio n. 1
0
        public async Task <Stream> Get <T>(RequestType requestType, string query)
        {
            string     url    = TvDbHelper.GetGetUrl(_baseUrl, requestType, query);
            HttpClient client = new HttpClient {
                BaseAddress = new Uri(url)
            };

            if (requestType != RequestType.Login)
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _apitoken);
            }
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = Task.Run(() => client.GetAsync(url)).Result;

            return(await response.Content.ReadAsStreamAsync());
        }
Esempio n. 2
0
        private async Task <T> Post <T>(RequestType requestType, string jsonstring)
        {
            string     url    = TvDbHelper.GetPostUrl(_baseUrl, requestType);
            HttpClient client = new HttpClient {
                BaseAddress = new Uri(url)
            };

            if (requestType != RequestType.Login)
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _apitoken);
            }
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpContent content = new StringContent(jsonstring);

            content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
            HttpResponseMessage response = await client.PostAsync(url, content);

            var result = response.Content.ReadAsStringAsync().Result;

            return(JsonConvert.DeserializeObject <T>(result));
        }