Created
July 30, 2015 23:41
C# HTTP GET request synchronous example
This file contains hidden or 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); | |
} | |
} |
Isn't calling
.Result
a potential source for deadlocks and AsyncBridge should be used instead?
Yes, coincidently watched this today - found it very interesting and insightful.
https://www.youtube.com/watch?v=av5YNd4X3dY
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Isn't calling
.Result
a potential source for deadlocks and AsyncBridge should be used instead?