Skip to main content

Punk API 18hour Experiment - Step #1

Asynchronous Call using the HttpClient

            var response = await client.GetAsync(txtURL.Text);

            if (response.IsSuccessStatusCode)
            {
                var responseContent = response.Content;

                string responseString = await responseContent.ReadAsStringAsync();

                //Console.WriteLine(responseString);
                txtResults.Text = responseString;
            }

Synchronous Call using the HttpClient

            var response = client.GetAsync(txtURL.Text).Result;

            if (response.IsSuccessStatusCode)
            {
                var responseContent = response.Content;

                // by calling .Result you are synchronously reading the result
                string responseString = responseContent.ReadAsStringAsync().Result;

                //Console.WriteLine(responseString);
                txtResults.Text = responseString;
            }

Comments