So, through my research, I know you need to either "rewind" a stream before you read from it again, or you need to copy a stream.
I can't rewind this stream, so I must make a copy of it. I tried to do it below, but when I read from either stream, I end up reading 0 bytes
The documentation for CopyTo says that it "reads the stream".
Does this "reading" set the "read head" at the end, or am I just doing something else wrong?
public static void ListenerCallback(IAsyncResult result)
{
HttpListener listener = (HttpListener)result.AsyncState;
HttpListenerContext context = listener.EndGetContext(result);
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
System.IO.Stream stream = new System.IO.MemoryStream();
request.InputStream.CopyTo(stream);
StreamReader reader = new StreamReader(stream);
var res = reader.ReadToEnd(); //I should be seeing output here
reader.Close();
Console.WriteLine(res);
NameValueCollection coll = HttpUtility.ParseQueryString(res);
using (var outp = File.OpenWrite("output.pptx")) //This file should have data in it
{
request.InputStream.CopyTo(outp);
}
response.StatusCode = 200;
response.ContentType = "text/html";
using (StreamWriter writer = new StreamWriter(context.Response.OutputStream, Encoding.UTF8))
writer.WriteLine("File Uploaded");
response.Close();
stream.Close();
request.InputStream.Close();
}