Skip to content

Instantly share code, notes, and snippets.

@jahanson
Created October 13, 2013 22:42
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/6968214 to your computer and use it in GitHub Desktop.
Save jahanson/6968214 to your computer and use it in GitHub Desktop.
Asynchronous Http Post with data as C# web api.
// GET api/<controller>
async public Task<string> Get()
{
string strResponse = "";
HttpClient client = new HttpClient();
HttpContent responseContent;
HttpResponseMessage response;
var requestContent = new FormUrlEncodedContent(new[] {
new KeyValuePair<string,string>("text","this is a block of text"),
});
response = await client.PostAsync(
"https://api.domain.com",
requestContent);
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