Skip to content

Instantly share code, notes, and snippets.

@davidebbo
Created October 12, 2012 06:53
Show Gist options
  • Save davidebbo/3877685 to your computer and use it in GitHub Desktop.
Save davidebbo/3877685 to your computer and use it in GitHub Desktop.
Save the body of a request to a temp file
<%@ WebHandler Language="C#" Class="Handler" Debug="true" %>
using System;
using System.Web;
using System.IO;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string path = System.IO.Path.Combine(Path.GetTempPath(), "body");
using (var fileStream = File.OpenWrite(path))
{
CopyStream(context.Request.InputStream, fileStream);
}
}
public bool IsReusable
{
get
{
return false;
}
}
public static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[32768];
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment