static async Task <MonsterDetailed> HttpGetMonstersAsync(string url) { string result = null; HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.ContentType = "application/json"; request.Method = "GET"; // no post data, act as get request. request.ContentLength = 0; string responseData = string.Empty; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { responseData = reader.ReadToEnd(); reader.Close(); } response.Close(); } //using (HttpClient syncClient = new HttpClient()) //{ // var response = await syncClient.GetAsync(url); // result = await response.Content.ReadAsStringAsync(); //} MonsterDetailed currentMonsterList = JsonConvert.DeserializeObject <MonsterDetailed>(responseData); return(currentMonsterList); }
static async Task <MonsterDetailed> GetMonsterAsync(string monster) { string url; StringBuilder sb = new StringBuilder(); sb.Clear(); sb.Append("https://pokeapi.co/api/v2/pokemon/" + monster.ToLower() + "/"); url = sb.ToString(); MonsterDetailed currentMonster = new MonsterDetailed(); Task <MonsterDetailed> getCurrentMonsterList = HttpGetMonstersAsync(url); currentMonster = await getCurrentMonsterList; // Detail detailForm = new Detail(currentMonster); // detailForm.Show(); return(currentMonster); }
public Detail(MonsterDetailed monster) { InitializeComponent(); _monster = monster; }