locked
HttpClient RRS feed

  • Question

  • User1979860870 posted

    Hi

      In below code i want to know how below lines work

    client.GetAsync

    responseTask.Wait();

    var result = responseTask.Result;

    static void Main(string[] args)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:60464/api/");
                    //HTTP GET
                    var responseTask = client.GetAsync("student");
                    responseTask.Wait();
    
                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
    
                        var readTask = result.Content.ReadAsAsync<Student[]>();
                        readTask.Wait();
    
                        var students = readTask.Result;
    
                        foreach (var student in students)
                        {
                            Console.WriteLine(student.Name);
                        }
                    }
                }
                Console.ReadLine();
            }  

    Thanks

    Sunday, February 7, 2021 9:14 AM

Answers