Example #1
0
 public MainWindow()
 {
     forecast = null;
     client   = new HttpClient();
     InitializeComponent();
     getForecast();
 }
Example #2
0
        static async Task <ForecastKota> getForecasteKotaAsync(String path)
        {
            ForecastKota        forecastKota = null;
            HttpResponseMessage respon       = await client.GetAsync(path);

            if (respon.IsSuccessStatusCode)
            {
                forecastKota = await respon.Content.ReadAsAsync <ForecastKota>();
            }
            return(forecastKota);
        }
Example #3
0
        async Task getForecast()
        {
            client.BaseAddress = new Uri("http://api.openweathermap.org/data/2.5/weather");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            //string kota = "Malang";
            setKota();
            /* string kota = await getKota();*/
            string kota = "Malang";
            string key  = "{YOUR API KEY}";
            string path = "?q=" + kota + "&APPID=" + key;

            try
            {
                //GET
                forecast = await getForecasteKotaAsync(path);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }