Created
October 13, 2013 22:44
-
-
Save jahanson/6968238 to your computer and use it in GitHub Desktop.
Asynchronous Http Get with C# Web api.
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
// GET api/<controller> | |
async public Task<string> Get() | |
{ | |
string strResponse = ""; | |
HttpClient client = new HttpClient(); | |
HttpContent responseContent; | |
HttpResponseMessage response; | |
response = await client.GetAsync("https://api.domain.com"); | |
responseContent = response.Content; | |
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync())) | |
{ | |
strResponse = await reader.ReadToEndAsync(); | |
} | |
return strResponse; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment