Data IweatherDataService.GetWeatherData(Location loc, String key) { String urlParameters; urlParameters = "?q=" + loc.city + "," + loc.country + "&APPID=" + key; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL); // Add an Accept header for Json format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); // List data response. HttpResponseMessage response = client.GetAsync(urlParameters).Result; // Blocking call! if (response.IsSuccessStatusCode) { Console.WriteLine(response); // Parse the response body. Blocking! try { data = response.Content.ReadAsAsync <Data>().Result; Console.WriteLine("city:" + data.name + ", city ID:" + data.id); Console.WriteLine(data.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } return(data); }
public override string ToString() { return(Data.ToString()); }
Data IweatherDataService.GetWeatherData(Location loc, String key) { String urlParameters; urlParameters = "?q="+ loc.city + "," + loc.country + "&APPID=" + key; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL); // Add an Accept header for Json format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); // List data response. HttpResponseMessage response = client.GetAsync(urlParameters).Result; // Blocking call! if (response.IsSuccessStatusCode) { Console.WriteLine(response); // Parse the response body. Blocking! try { data = response.Content.ReadAsAsync<Data>().Result; Console.WriteLine("city:" + data.name + ", city ID:" + data.id); Console.WriteLine(data.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } return data; }