Created
July 30, 2015 23:41
-
-
Save dantheman213/a39684b7824e30f445e5 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
Yes, coincidently watched this today - found it very interesting and insightful.
https://www.youtube.com/watch?v=av5YNd4X3dY