Skip to content

Instantly share code, notes, and snippets.

@jahanson
Created October 13, 2013 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahanson/6968238 to your computer and use it in GitHub Desktop.
Save jahanson/6968238 to your computer and use it in GitHub Desktop.
Asynchronous Http Get with C# Web api.
// 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