Exemplo n.º 1
0
        string GetURLstringFromBody(LogInBody o)
        {
            List <string> polje = new List <string>();

            foreach (var property in o.GetType().GetProperties())
            {
                polje.Add((property.Name).ToLower() + "=" + Uri.EscapeDataString(property.GetValue(o).ToString()));
            }
            string s = string.Join("&", polje);

            return(s);
        }
Exemplo n.º 2
0
        public async Task <BearerToken> AuthentificateAsync(Uri url, LogInBody o)
        {
            var client  = new HttpClient();
            var content = new StringContent(GetURLstringFromBody(o), Encoding.UTF8, "application/x-www-form-urlencoded");
            HttpResponseMessage response = null;

            response = await client.PostAsync(url, content);

            if (!response.IsSuccessStatusCode)
            {
                return(null);
            }
            var result = await response.Content.ReadAsStringAsync();

            IsoDateTimeConverter dateTimeConverter = new IsoDateTimeConverter {
                DateTimeFormat = "R"
            };
            BearerToken b = JsonConvert.DeserializeObject <BearerToken>(result, dateTimeConverter);

            return(b);
        }