Esempio n. 1
0
        public async void GenerateRequest()
        {
            Dictionary <string, string> _contentValues = new Dictionary <string, string>();

            _contentValues.Add("username", dataBind.UserName);
            _contentValues.Add("password", dataBind.Password);
            var content  = new FormUrlEncodedContent(_contentValues);
            var response = await client.PostAsync("http://playground.tesonet.lt/v1/tokens", content);

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException("Issue with request check username/password");
            }
            var responseString = await response.Content.ReadAsStringAsync();

            Token token = JsonConvert.DeserializeObject <Token>(responseString);

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token.token);
            var servers = await client.GetAsync("http://playground.tesonet.lt/v1/servers");

            var serverResponse = await servers.Content.ReadAsStringAsync();

            parent.SetListToDataBind(JsonConvert.DeserializeObject <List <Server> >(serverResponse));
        }