Skip to content

Instantly share code, notes, and snippets.

@leggetter
Created January 7, 2011 16:23
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save leggetter/769688 to your computer and use it in GitHub Desktop.
Save leggetter/769688 to your computer and use it in GitHub Desktop.
How to get the body of a HTTP Request using C#
private string GetDocumentContents(System.Web.HttpRequestBase Request)
{
string documentContents;
using (Stream receiveStream = Request.InputStream)
{
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
{
documentContents = readStream.ReadToEnd();
}
}
return documentContents;
}
@winperec
Copy link

You should be careful with disposing! if you look at native BinaryRead method - it uses InputStream as well but does not dispose it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment