public static HttpClient GetClient(string requestedVersion = null)
        {

            CheckAndPossiblyRefreshToken((HttpContext.Current.User.Identity as ClaimsIdentity));

            HttpClient client = new HttpClient();            

            var token = (HttpContext.Current.User.Identity as ClaimsIdentity).FindFirst("access_token");
            if (token != null)
            {
                client.SetBearerToken(token.Value);
            }

            client.BaseAddress = new Uri(ExpenseTrackerConstants.ExpenseTrackerAPI);

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            if (requestedVersion != null)
            {
                // through a custom request header
                //client.DefaultRequestHeaders.Add("api-version", requestedVersion);

                // through content negotiation
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/vnd.expensetrackerapi.v" 
                        + requestedVersion + "+json"));
            }


            return client;
        }
Example #2
0
 /// <summary>
 /// Chama a api do AppService com um token valido.
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 private async Task<string> CallApi(string token) 
 {
     var client = new HttpClient();
     client.SetBearerToken(token);
     var json = await client.GetStringAsync("https://localhost:44303/identity");
     return JArray.Parse(json).ToString();
 }
        public async Task<IActionResult> CallApi()
        {
            var accessToken = User.Claims.SingleOrDefault(claim => claim.Type == "access_token");

            if (accessToken == null)
            {
                return new BadRequestResult();
            }

            HttpClient client = new HttpClient();

            // The Resource API will validate this access token
            client.SetBearerToken(accessToken.Value);
            client.BaseAddress = new Uri(Constants.ResourceApi);

            HttpResponseMessage response = await client.GetAsync("api/Tickets/Read");

            if (!response.IsSuccessStatusCode)
            {
                return new BadRequestObjectResult("Error connecting with the API");
            }

            var responseContent = await response.Content.ReadAsStringAsync();

            return new ObjectResult(responseContent);
        }
Example #4
0
        static String CallApi(TokenResponse response)
        {
            var client = new HttpClient();
            client.SetBearerToken(response.AccessToken);

            return client.GetStringAsync(Constants.ApiUrl + "/test").Result;
        }
Example #5
0
        public static System.Net.Http.HttpClient GetClient(string requestedVersion = null)
        {
            CheckAndPossiblyRefreshToken((HttpContext.Current.User.Identity as ClaimsIdentity));

            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();

            var token = (HttpContext.Current.User.Identity as ClaimsIdentity).FindFirst("access_token");

            if (token != null)
            {
                client.SetBearerToken(token.Value);
            }

            client.BaseAddress = new Uri(Constants.Constants.MedicoApiBaseAddress);

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            if (requestedVersion != null)
            {
                // through a custom request header
                //client.DefaultRequestHeaders.Add("api-version", requestedVersion);

                // through content negotiation
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/vnd.medicoapi.v"
                                                        + requestedVersion + "+json"));
            }


            return(client);
        }
        static void CallApi(TokenResponse response)
        {
            var client = new HttpClient();
            client.SetBearerToken(response.AccessToken);

            Console.WriteLine(client.GetStringAsync("http://localhost:44334/test").Result);
        }
		static void Main(string[] args)
		{
			var tokenClient = new TokenClient(
				"http://localhost:18942/connect/token",
				"test",
				"secret");

			//This responds with the token for the "api" scope, based on the username/password above
			var response = tokenClient.RequestClientCredentialsAsync("api1").Result;

			//Test area to show api/values is protected
			//Should return that the request is unauthorized
			try
			{
				var unTokenedClient = new HttpClient();
				var unTokenedClientResponse = unTokenedClient.GetAsync("http://localhost:19806/api/values").Result;
				Console.WriteLine("Un-tokened response: {0}", unTokenedClientResponse.StatusCode);
			}
			catch (Exception ex)
			{
				Console.WriteLine("Exception of: {0} while calling api without token.", ex.Message);
			}


			//Now we make the same request with the token received by the auth service.
			var client = new HttpClient();
			client.SetBearerToken(response.AccessToken);

			var apiResponse = client.GetAsync("http://localhost:19806/identity").Result;
			var callApiResponse = client.GetAsync("http://localhost:19806/api/values").Result;
			Console.WriteLine("Tokened response: {0}", callApiResponse.StatusCode);
			Console.WriteLine(callApiResponse.Content.ReadAsStringAsync().Result);
			Console.Read();
		}
        public static HttpClient GetClient()
        {
            if (currentClient == null)
            {
                var accessToken = App.ExpenseTrackerIdentity.Claims.First
                    (c => c.Name == "access_token").Value;

                currentClient = new HttpClient(new Marvin.HttpCache.HttpCacheHandler()
                {
                    InnerHandler = new HttpClientHandler()
                });

                currentClient.SetBearerToken(accessToken);
                           

                currentClient.BaseAddress = new Uri(ExpenseTrackerConstants.ExpenseTrackerAPI);

                currentClient.DefaultRequestHeaders.Accept.Clear();
                currentClient.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));
 
            }

            return currentClient;
        }
 private static string CallApi(string token)
 {
     var client = new HttpClient();
     client.SetBearerToken(token);
     var result = client.GetStringAsync(ApplicationConstants.UrlBaseApi + "/api/test").Result;
     return result;
 }
Example #10
0
        private async Task<string> CallApi(string token)
        {
            var client = new HttpClient();
            client.SetBearerToken(token);

            var json = await client.GetStringAsync("http://localhost:32227/api/values");
            return json;
        }
        protected async Task<string> CallApi(string token, string url)
        {
            var client = new HttpClient();
            client.SetBearerToken(token);

            var json = await client.GetStringAsync(url);
            return JArray.Parse(json).ToString();
        }
        private async Task<string> CallApi(string token)
        {
            var client = new HttpClient();
            client.SetBearerToken(token);

            var json = await client.GetStringAsync(IdConstants.IdHost + "identity");
            return JArray.Parse(json).ToString();
        }
 private async Task<String> GetUserInfos()
 {
     var user = User as ClaimsPrincipal;
     var token = user.FindFirst("access_token").Value;
     var client = new HttpClient();
     client.SetBearerToken(token);
     HttpResponseMessage response = await client.GetAsync("https://localhost:44333/core/connect/userinfo");
     return await response.Content.ReadAsStringAsync();
 }
Example #14
0
        /// <summary>
        /// Get a token before making a GET request to the specified api path
        /// </summary>
        /// <param name="route"></param>
        /// <returns></returns>
        public static string CallApi(string path)
        {
            string token = GetToken();
            //string token = GetTokenExplained();
            var client = new HttpClient();
            client.SetBearerToken(token);

            return client.GetStringAsync(ConfigurationManager.AppSettings["Api"] + "/" + path).Result;
        }
        static void Main(string[] args)
        {
            var response = GetToken();

            var client = new HttpClient();
            client.SetBearerToken(response.AccessToken);

            var result = client.GetStringAsync("http://localhost:2025/claims").Result;
            Console.WriteLine(JArray.Parse(result));
        }
        private async static Task ResourceOwnerFlow()
        {
            var oauthClient = new OAuth2Client(new Uri("http://localhost:1642/token"));
            var tokenResponse = oauthClient.RequestResourceOwnerPasswordAsync("cecil", "cecil").Result;

            var client = new HttpClient();
            client.SetBearerToken(tokenResponse.AccessToken);
            var response = await client.GetStringAsync(new Uri("http://localhost:1642/api/secure/data"));

            Console.WriteLine(response);
        }
        public async Task<ActionResult> CallService()
        {
            var principal = User as ClaimsPrincipal;

            var client = new HttpClient();
            client.SetBearerToken(principal.FindFirst("access_token").Value);

            var result = await client.GetStringAsync(Constants.AspNetWebApiSampleApi + "identity");

            return View(JArray.Parse(result));
        }
        private async Task<JArray> CallApiAsync(string token)
        {
            var client = new HttpClient();
            client.SetBearerToken(token);

            var response = await client.GetAsync("https://localhost:44347/test");
            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();
            return JArray.Parse(content);
        }
        public async Task<IActionResult> CallApi()
        {
            var token = User.FindFirst("access_token").Value;

            var client = new HttpClient();
            client.SetBearerToken(token);

            var response = await client.GetStringAsync("http://localhost:3860/identity");
            ViewBag.Json = JArray.Parse(response).ToString();

            return View();
        }
		public void ProcessRequestRunTestScript()
		{
			using (WebApp.Start<Startup>("http://localhost:9000"))
			{
				var client = new HttpClient { BaseAddress = new Uri("http://localhost:9000") };
				client.SetBearerToken(IssueToken());
				var response = client.GetAsync("/api/Exchange/CreateMailbox?MailBoxSize=99").Result;

				Assert.AreNotEqual(HttpStatusCode.Unauthorized, response.StatusCode, "Could not authenticate!");
				Assert.IsTrue(response.IsSuccessStatusCode, "Response was not successful.");
			}
		}
        public async Task<ActionResult> CallApi()
        {
            var token = (User as ClaimsPrincipal).FindFirst("access_token").Value;

            var client = new HttpClient();
            client.SetBearerToken(token);

            var result = await client.GetStringAsync(Constants.AspNetWebApiSampleApi + "identity");
            ViewBag.Json = JArray.Parse(result.ToString());

            return View();
        }
		private async Task<String> GetResourceWithId(Int32 id)
		{
			var user = User as ClaimsPrincipal;
			var token = user.FindFirst("access_token").Value;

			var client = new HttpClient();
			client.SetBearerToken(token);

			HttpResponseMessage response = await client.GetAsync("http://localhost:10070/api/students");

			return await response.Content.ReadAsStringAsync();
		}
Example #23
0
        public async Task<IActionResult> CallApi()
        {
            var token = User.FindFirst("access_token").Value;

            var client = new HttpClient();
            client.SetBearerToken(token);

            //WebApi Url
            var response = await client.GetStringAsync(URLS.Api_url+"identity");
            ViewBag.Json = JArray.Parse(response).ToString();

            return View();
        }
Example #24
0
        public async Task <IActionResult> CallApiUsingUserAccessToken()
        {
            var accessToken = await HttpContext.GetTokenAsync("access_token");

            var client = new System.Net.Http.HttpClient();

            client.SetBearerToken(accessToken);
            //client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
            var content = await client.GetStringAsync("http://localhost:5001/api/values");

            ViewBag.Json = JArray.Parse(content).ToString();
            return(View("json"));
        }
Example #25
0
		public static HttpClient GetClient()
		{
			HttpClient client = new HttpClient();
			var token = RequestTokenAuthorizationCode();
			if(!string.IsNullOrEmpty(token))
				client.SetBearerToken(token);
			client.BaseAddress = new Uri(IdealConstants.ApiOriginUrl);

			client.DefaultRequestHeaders.Accept.Clear();
			client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

			return client;
		}
 private async void GetEmployees()
 {
     using (HttpClient client = new HttpClient())
     {
         client.SetBearerToken(ApplicationVM.token.AccessToken);
         HttpResponseMessage response = await client.GetAsync("http://localhost:27809/api/registersemployee");
         if (response.IsSuccessStatusCode)
         {
             string json = await response.Content.ReadAsStringAsync();
             _employeesOriginal = JsonConvert.DeserializeObject<ObservableCollection<RegisterEmployee>>(json);
             Employees = _employeesOriginal;
         }
     }
 }
        private async Task<String> CreateCourse(Course course)
        {
            var user = User as ClaimsPrincipal;
            var token = user.FindFirst("access_token").Value;
            var claims = user.Claims.ToString();

            var client = new HttpClient();
            client.SetBearerToken(token);
            string json = JsonConvert.SerializeObject(course);
            StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
            var response = client.PostAsync("http://localhost:10072/api/courses/create", content).Result;

            return await response.Content.ReadAsStringAsync();
        }
Example #28
0
        static void CallService(string token)
        {
            var baseAddress = Constants.AspNetWebApiSampleApi;

            var client = new HttpClient
            {
                BaseAddress = new Uri(baseAddress)
            };

            client.SetBearerToken(token);
            var response = client.GetStringAsync("identity").Result;

            "\n\nService claims:".ConsoleGreen();
            Console.WriteLine(JArray.Parse(response));
        }
Example #29
0
 private async void GetRegisters()
 {
     using (HttpClient client = new HttpClient())
     {
         client.SetBearerToken(ApplicationVM.token.AccessToken);
         HttpResponseMessage response = await client.GetAsync("http://localhost:27809/api/registersclient");
         if (response.IsSuccessStatusCode)
         {
             string json = await response.Content.ReadAsStringAsync();
             Registers = JsonConvert.DeserializeObject<ObservableCollection<Register>>(json);
             //if (Products.Count > 0)
             //SelectedRegister = Registers.First();
         }
     }
 }
Example #30
0
        private static void callService(string token)
        {
            var client = new HttpClient
                {
                    BaseAddress = new Uri("https://localhost:44308")
                };

            client.SetBearerToken(token);

            var response = client.GetAsync("Home/Get").Result;

            response.EnsureSuccessStatusCode();

            var result = response.Content.ReadAsStringAsync().Result;
        }
        static void Main(string[] args)
        {
            var tokenClient = new TokenClient(
                "http://localhost:5000/connect/token",
                "test",
                "secret");

            var response = tokenClient.RequestClientCredentialsAsync("api1").Result;

            var client = new HttpClient();
            client.SetBearerToken(response.AccessToken);

            var apiResponse = client.GetAsync("http://localhost:19806/identity").Result;
            Console.WriteLine(apiResponse.StatusCode);
        }
Example #32
0
        private async void btnApiAccess_Click(object sender, EventArgs e)
        {
            var claim = await GetClaimsAsync(UserAccessInfo.AccessToken);

            var query = from info in claim where info.Item1 == UGConstants.ClaimTypes.PreferredUserName select info.Item2;
            string userName = string.Empty;
            if (query.Count() > 0)
                userName = query.First();

            var client = new HttpClient();
            client.SetBearerToken(UserAccessInfo.AccessToken);
            client.DefaultRequestHeaders.Add(UGConstants.HTTPHeaders.IOT_CLIENT_ID, IoTClientId);
            client.DefaultRequestHeaders.Add(UGConstants.HTTPHeaders.IOT_CLIENT_SECRET, IoTClientSecret);
            client.DefaultRequestHeaders.Add(UGConstants.ClaimTypes.PreferredUserName, userName);

            BaseMessage msg = new BaseMessage("", "", SSD.Framework.Exceptions.ErrorCode.IsSuccess, "");
            msg.MsgJson = "{\"LocationStoreID\":1,\"ID\":1}";
            StringContent queryString = new StringContent(msg.ToJson());
            var response = await client.PostAsync(APIUri,queryString);

            if (response.IsSuccessStatusCode)
            {
                string contentStr = string.Empty;

                IEnumerable<string> lst;
                if (response.Content.Headers != null
                    && response.Content.Headers.TryGetValues(UGConstants.HTTPHeaders.CONTENT_ENCODING, out lst)
                    && lst.First().ToLower() == "deflate")
                {
                    var bj = await response.Content.ReadAsByteArrayAsync();
                    using (var inStream = new MemoryStream(bj))
                    {
                        using (var bigStreamsss = new DeflateStream(inStream, CompressionMode.Decompress, true))
                        {
                            contentStr = await (new StreamReader(bigStreamsss)).ReadToEndAsync();
                            //using (var bigStreamOut = new MemoryStream())
                            //{
                            //    bigStreamsss.CopyTo(bigStreamOut);
                            //    contentStr = Encoding.UTF8.GetString(bigStreamOut.ToArray(), 0, bigStreamOut.ToArray().Length);
                            //}
                        }

                    }
                }
                else contentStr = await response.Content.ReadAsStringAsync();
                MessageBox.Show(contentStr);
            }
        }
Example #33
0
        public async Task <System.Net.Http.HttpClient> GetClient()
        {
            // In order to access API, the web client needs passing an Access Token to API. And the token should be passed as bearer token.

            string accessToken = await GetValidAccessToken();

            if (!string.IsNullOrEmpty(accessToken))
            {
                // Passing an access token to the web api on each request.
                _httpClient.SetBearerToken(accessToken); // The token should be passed as bearer token.
            }

            _httpClient.BaseAddress = new Uri("https://localhost:44396/"); // this is url of web api.
            _httpClient.DefaultRequestHeaders.Accept.Clear();
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            return(_httpClient);
        }
Example #34
0
 public async Task SetAuthentication(System.Net.Http.HttpClient client)
 {
     client.SetBearerToken(await TokenCache.GetAccessToken());
 }
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>Success</returns>
        /// <exception cref="ApiException">A server side error occurred.</exception>
        public async System.Threading.Tasks.Task <VtVoidTicketsLostInspection> FinishVoidTicketAsync(int?id, int?inspectionid, int?dispatchid, int?locked, int?losttypeid, int?competitorid, int?reasonlostid, string reasonotherdesc, string othercompdesc, string spoketosomeone, string personspoketo, string physicalstopby, string physicalstopbydate, string lastinspection, string comments, string customerservice, string user, string ticketnumber, string googlemainnumber, TokenResponse requestTokeResponse, System.Threading.CancellationToken cancellationToken)
        {
            var urlBuilder_ = new System.Text.StringBuilder();

            urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/VoidTicket/FinishVoid?");
            if (id != null)
            {
                urlBuilder_.Append("id=").Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (inspectionid != null)
            {
                urlBuilder_.Append("inspectionid=").Append(System.Uri.EscapeDataString(ConvertToString(inspectionid, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (dispatchid != null)
            {
                urlBuilder_.Append("dispatchid=").Append(System.Uri.EscapeDataString(ConvertToString(dispatchid, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (locked != null)
            {
                urlBuilder_.Append("locked=").Append(System.Uri.EscapeDataString(ConvertToString(locked, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (losttypeid != null)
            {
                urlBuilder_.Append("losttypeid=").Append(System.Uri.EscapeDataString(ConvertToString(losttypeid, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (competitorid != null)
            {
                urlBuilder_.Append("competitorid=").Append(System.Uri.EscapeDataString(ConvertToString(competitorid, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (reasonlostid != null)
            {
                urlBuilder_.Append("reasonlostid=").Append(System.Uri.EscapeDataString(ConvertToString(reasonlostid, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (reasonotherdesc != null)
            {
                urlBuilder_.Append("reasonotherdesc=").Append(System.Uri.EscapeDataString(ConvertToString(reasonotherdesc, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (othercompdesc != null)
            {
                urlBuilder_.Append("othercompdesc=").Append(System.Uri.EscapeDataString(ConvertToString(othercompdesc, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (spoketosomeone != null)
            {
                urlBuilder_.Append("spoketosomeone=").Append(System.Uri.EscapeDataString(ConvertToString(spoketosomeone, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (personspoketo != null)
            {
                urlBuilder_.Append("personspoketo=").Append(System.Uri.EscapeDataString(ConvertToString(personspoketo, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (physicalstopby != null)
            {
                urlBuilder_.Append("physicalstopby=").Append(System.Uri.EscapeDataString(ConvertToString(physicalstopby, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (physicalstopbydate != null)
            {
                urlBuilder_.Append("physicalstopbydate=").Append(System.Uri.EscapeDataString(ConvertToString(physicalstopbydate, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (lastinspection != null)
            {
                urlBuilder_.Append("lastinspection=").Append(System.Uri.EscapeDataString(ConvertToString(lastinspection, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (comments != null)
            {
                urlBuilder_.Append("comments=").Append(System.Uri.EscapeDataString(ConvertToString(comments, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (customerservice != null)
            {
                urlBuilder_.Append("customerservice=").Append(System.Uri.EscapeDataString(ConvertToString(customerservice, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (user != null)
            {
                urlBuilder_.Append("user="******"&");
            }
            if (ticketnumber != null)
            {
                urlBuilder_.Append("ticketnumber=").Append(System.Uri.EscapeDataString(ConvertToString(ticketnumber, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            if (googlemainnumber != null)
            {
                urlBuilder_.Append("googlemainnumber=").Append(System.Uri.EscapeDataString(ConvertToString(googlemainnumber, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
            }
            urlBuilder_.Length--;

            var client_ = new System.Net.Http.HttpClient();

            client_.SetBearerToken(requestTokeResponse.AccessToken);
            try
            {
                using (var request_ = new System.Net.Http.HttpRequestMessage())
                {
                    request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json");
                    request_.Method  = new System.Net.Http.HttpMethod("PUT");
                    request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));

                    PrepareRequest(client_, request_, urlBuilder_);
                    var url_ = urlBuilder_.ToString();
                    request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
                    PrepareRequest(client_, request_, url_);

                    var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);

                    try
                    {
                        var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
                        if (response_.Content != null && response_.Content.Headers != null)
                        {
                            foreach (var item_ in response_.Content.Headers)
                            {
                                headers_[item_.Key] = item_.Value;
                            }
                        }

                        ProcessResponse(client_, response_);

                        var status_ = ((int)response_.StatusCode).ToString();
                        if (status_ == "404")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <ProblemDetails>(response_, headers_).ConfigureAwait(false);

                            throw new ApiException <ProblemDetails>("Not Found", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null);
                        }
                        else
                        if (status_ == "200")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <VtVoidTicketsLostInspection>(response_, headers_).ConfigureAwait(false);

                            return(objectResponse_.Object);
                        }
                        else
                        if (status_ == "400")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <ProblemDetails>(response_, headers_).ConfigureAwait(false);

                            throw new ApiException <ProblemDetails>("Bad Request", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null);
                        }
                        else
                        if (status_ != "200" && status_ != "204")
                        {
                            var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);

                            throw new ApiException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null);
                        }

                        return(default(VtVoidTicketsLostInspection));
                    }
                    finally
                    {
                        if (response_ != null)
                        {
                            response_.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (client_ != null)
                {
                    client_.Dispose();
                }
            }
        }
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>Success</returns>
        /// <exception cref="ApiException">A server side error occurred.</exception>
        public async System.Threading.Tasks.Task <System.Collections.Generic.ICollection <ArUserdef8> > GetCompetitorsAsync(TokenResponse requestTokeResponse, System.Threading.CancellationToken cancellationToken)
        {
            var urlBuilder_ = new System.Text.StringBuilder();

            urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Competitor");

            var client_ = new System.Net.Http.HttpClient();

            //***********setting bearer token
            client_.SetBearerToken(requestTokeResponse.AccessToken);
            try
            {
                using (var request_ = new System.Net.Http.HttpRequestMessage())
                {
                    request_.Method = new System.Net.Http.HttpMethod("GET");
                    request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));

                    PrepareRequest(client_, request_, urlBuilder_);
                    var url_ = urlBuilder_.ToString();
                    request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
                    PrepareRequest(client_, request_, url_);

                    var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);

                    try
                    {
                        var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
                        if (response_.Content != null && response_.Content.Headers != null)
                        {
                            foreach (var item_ in response_.Content.Headers)
                            {
                                headers_[item_.Key] = item_.Value;
                            }
                        }

                        ProcessResponse(client_, response_);

                        var status_ = ((int)response_.StatusCode).ToString();
                        if (status_ == "404")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <ProblemDetails>(response_, headers_).ConfigureAwait(false);

                            throw new ApiException <ProblemDetails>("Not Found", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null);
                        }
                        else
                        if (status_ == "200")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <System.Collections.Generic.ICollection <ArUserdef8> >(response_, headers_).ConfigureAwait(false);

                            return(objectResponse_.Object);
                        }
                        else
                        if (status_ == "400")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <ProblemDetails>(response_, headers_).ConfigureAwait(false);

                            throw new ApiException <ProblemDetails>("Bad Request", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null);
                        }
                        else
                        if (status_ != "200" && status_ != "204")
                        {
                            var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);

                            throw new ApiException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null);
                        }

                        return(default(System.Collections.Generic.ICollection <ArUserdef8>));
                    }
                    finally
                    {
                        if (response_ != null)
                        {
                            response_.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (client_ != null)
                {
                    client_.Dispose();
                }
            }
        }