Created
October 12, 2012 06:53
-
-
Save davidebbo/3877685 to your computer and use it in GitHub Desktop.
Save the body of a request to a temp file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ 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