Пример #1
0
 private static async Task<string> GetToken()
 {
     var result = await CustomHttpClient.GetTokenAccess(url, "rafadu", "916152");
     TokenResult token = JsonConvert.DeserializeObject<TokenResult>(result);
     if (token.error != null)
         return null;
     expire = DateTime.Now.AddSeconds(Convert.ToDouble(token.expires_in));
     accessToken = token.access_token;
     client = new CustomHttpClient(url, accessToken);
     return string.Empty;
 }
Пример #2
0
        public static async Task DoWork()
        {
            string url = ConfigurationManager.AppSettings["address"];
            var result = await CustomHttpClient.GetTokenAccess(url, "rafadu", "916153");
            TokenResult token = JsonConvert.DeserializeObject<TokenResult>(result);
            Console.WriteLine("Token: " + token.access_token);
            Console.WriteLine();
            var client = new CustomHttpClient(url, token.access_token);

            //var userRequestModel = new UserRequestModel() { Login = "******", Password = "******", IdRole = Convert.ToInt32(EnumIdRole.Admin) };

            //var jsonContent = new System.Net.Http.StringContent(JsonConvert.SerializeObject(userRequestModel),Encoding.UTF8,"application/json");

            //var postResult = await client.PostAsync("api/Membership", jsonContent);
            //result = await postResult.Content.ReadAsStringAsync();
            //Console.WriteLine("POST Result: " + result);

            var getResult = await client.GetAsync("api/Membership");
            result = await getResult.Content.ReadAsStringAsync();
            Console.WriteLine("GET Result: " + result);
            Console.ReadLine();
        }