I've got a little class that accepts a POST from a browser that contains file uploads. I'm using a StreamReader to read it in. I read the header, then when I get to the body, I get the content length and make an array of that size and then stream.ReadBlock()
on that:
char[] buffer = new char[contentLength];
stream.ReadBlock(buffer, 0, contentLength);
String body = new string(buffer);
When I run this and POST a text file, it works fine. However, I've tried both a ZIP file and an MP3 file, and neither of those work. It just hangs on the stream.ReadBlock()
call.
I tried this first on Ubuntu 10.04 with Mono 2.6.7 (my MonoDevelop Project is set to use .net 3.5). And I just verified the same thing happens on Windows7 by running the same project in VisualStudio 2010 and .net 3.5. I've tried posting from both Firefox, and Chrome.
Anyone have any clue why this would be happening? Thanks.
I also tried using a BinaryReader instead of a StreamReader:
byte[] bytes = reader.ReadBytes(contentLength);
but it ends up hanging on that call no matter what now. Is it because I use a StreamReader to read the header of the POST and then use a BinaryReader to read the body?