-
-
Save rswilley/8d02e044ab169527814593e691de1d83 to your computer and use it in GitHub Desktop.
C# HTTP GET request synchronous example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net.Http; | |
using (var client = new HttpClient()) | |
{ | |
var url = "http://google.com/api-example"; | |
var response = client.GetAsync(url).Result; | |
if (response.IsSuccessStatusCode) | |
{ | |
// by calling .Result you are performing a synchronous call | |
var responseContent = response.Content; | |
// by calling .Result you are synchronously reading the result | |
string responseString = responseContent.ReadAsStringAsync().Result; | |
Console.WriteLine(responseString); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment