Posts

Showing posts with the label restsharp

OAuth2 Bearer Token not getting sent with RestSharp call

Image
Clash Royale CLAN TAG #URR8PPP OAuth2 Bearer Token not getting sent with RestSharp call Credentials are right, because I can get an API response using PS with the same client id and secret . The token isn't invalid, but it won't get attached correctly to the rest request API response PS client id secret Unauthorized. Access token is missing or invalid Here's my code: var client = new RestClient(url); client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator("Bearer: " + OAuthToken); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddHeader("Accept", "application/json"); foreach (var paramName in parameters.Keys) { request.AddParameter(paramName, parameters[paramName]); } request.RequestFormat = DataFormat.Json; IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { string rawRespons...

RestSharp.RestClient.ExecuteTaskAsync Waiting Forever

Image
Clash Royale CLAN TAG #URR8PPP RestSharp.RestClient.ExecuteTaskAsync Waiting Forever I tried to look for a solution from RestSharp docs, examples, and stack overflow posts but found nothing that is applicable to my situation. What I'm trying to do here is to send multiple async requests at the same time, and waiting for all of them to come back with their response before proceeding - consuming data at the same time. However, the program hangs on Task.WaitAll. public List<CatalogModel> GetCatalogListAsync(string url, List<string> handles) { tasks = new List<Task<IRestResponse<CatalogModel>>>(); foreach (var handle in handles) { var task = GetCatalogTaskAsync(url, handle); tasks.Add(task); } var tasksArray = tasks.ToArray(); Task.WaitAll(tasksArray); var catalogList = new List<CatalogModel>(); foreach (var task in tasksArray) { var r...