Kód pro získání počasí v C#
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
private static readonly HttpClient client = new HttpClient();
static async Task Main()
{
string mesto = "Karlovy_Vary";
string url = $"https://wttr.in/{mesto}?format=%C+%t"; // Veřejné API pro počasí
try
{
HttpResponseMessage odpoved = await client.GetAsync(url);
odpoved.EnsureSuccessStatusCode();
string zprava = await odpoved.Content.ReadAsStringAsync();
Console.WriteLine("Počasí ve městě " + mesto + ":");
Console.WriteLine(zprava);
}
catch (HttpRequestException e)
{
Console.WriteLine($"Error: {e.Message}");
}
}
}