Skip to content

Instantly share code, notes, and snippets.

@andy-williams
Last active December 22, 2015 21: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 andy-williams/1532415b48dff1430201 to your computer and use it in GitHub Desktop.
Save andy-williams/1532415b48dff1430201 to your computer and use it in GitHub Desktop.
.NET HttpClient Warning
void Main()
{
using(var stream = File.Open(@"D:\test.txt", FileMode.Open))
using(var httpClient = new HttpClient())
{
stream.Dump();
var httpContent = new StreamContent(stream);
// pretty sweet test server by Henry Cipolla
// http://henrycipollablog.com/2011/12/06/testing-multipartform-data-uploads-with-post-test-server/
var result = httpClient.PostAsync("http://posttestserver.com/post.php?dir=httpclient-test", httpContent).Result;
stream.Dump(); // stream closed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment