public static void ShowCategoryJoke(string userInput) { string categoryChoiceUrl = $"https://api.chucknorris.io/jokes/random?category={userInput}"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(categoryChoiceUrl); request.Method = "GET"; var webResponse = request.GetResponse(); var webStream = webResponse.GetResponseStream(); using (var responseReader = new StreamReader(webStream)) { var response = responseReader.ReadToEnd(); //loeb maha kõik sümbolid mida ta saab serverist kätte Joke randomJoke = JsonConvert.DeserializeObject <Joke>(response); Console.WriteLine(randomJoke.Value); } }
public static void ShowRandomJoke() { string randomJokeUrl = "https://api.chucknorris.io/jokes/random"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(randomJokeUrl); request.Method = "GET"; var webResponse = request.GetResponse(); var webStream = webResponse.GetResponseStream(); using (var responseReader = new StreamReader(webStream)) { var response = responseReader.ReadToEnd(); Joke randomJoke = JsonConvert.DeserializeObject <Joke>(response); Console.WriteLine(randomJoke.Value); } }
static void Main(string[] args) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; var webResponse = request.GetResponse(); var webStream = webResponse.GetResponseStream(); using (var responseReader = new StreamReader(webStream)) { var response = responseReader.ReadToEnd(); Joke joke = JsonConvert.DeserializeObject <Joke>(response); Console.WriteLine($"Joke {joke.Id}: {joke.Value} "); } }
private static void CategoryByUser() { Console.WriteLine("\nChoose a category?"); string userCat = Console.ReadLine(); string categoryChoiceURL = ($"https://api.chucknorris.io/jokes/random?category={userCat}"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(categoryChoiceURL); request.Method = "GET"; var webResponse = request.GetResponse(); var webStream = webResponse.GetResponseStream(); using (var responseReader = new StreamReader(webStream)) { var response = responseReader.ReadToEnd(); Joke randomJoke = JsonConvert.DeserializeObject <Joke>(response); Console.WriteLine(randomJoke.Value); } }
public static void ShowRandomJokes() { string randomJokeUrl = "https://api.chucknorris.io/jokes/random"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(randomJokeUrl); //lõime kutset serveriga //täpsustame meetodi ehk GET meetod request.Method = "GET"; var webResponse = request.GetResponse(); //var on üldine, wevresponse-l pole kindlat tüüpi andmeid, //tagastab vastuse serverist ja salvestab sinna webResponse sisse. var webStream = webResponse.GetResponseStream(); // teeb ühenduse lahti ja saab andmeid lugeda (teeb //lahti loeb ja paneb kinni). Nii on turvalisem kui hoida andmed alati lahti using (var responseReader = new StreamReader(webStream)) { var response = responseReader.ReadToEnd(); //loeb maha kõik sümbolid mida ta saab serverist kätte Joke randomJoke = JsonConvert.DeserializeObject <Joke>(response); Console.WriteLine(randomJoke.Value); } }