How to save video/MP4 from POST body in C#
<p>I have set up motion detection on an IP camera (Sercomm RC8021) using an HTTP POST. Upon detecting motion, the camera initiates an HTTP POST, attaching an MP$ video in the post body. I have an ASP.NET page with C# code-behind attempting to save the file:</p>

<pre><code>    protected void Page_Load(object sender, EventArgs e)
    {
        String filename = "~/MotionDetectAttachment.mp4";
        this.Context.Request.SaveAs(Server.MapPath(filename), false);
    }
</code></pre>

<p>The problem is that the server sends an HTTP 500 code back to the camera and the file is not saved. Using wireshark, the communication seems to be fine until wireshark tags a packet with "TCP Window Full", followed by a series of ZeroWindow and Keep-Alive messages. Eventually the connection is reset, and the camera logs a 500 response from the server.</p>

<p>Any ideas on what I'm doing wrong? Other answers to similar questions refer to SaveAs being a way to save to file, but none of the other questions I read mentioned the wireshark issues.</p>

<p>Camera log sample:</p>

<blockquote>
  <p>11/02/2012 11:38:35 HTTP-POST:Failed to post file [HTTP error code: 500].<br>
  11/02/2012 11:38:03 Alert: Detected motion.</p>
</blockquote>

<p>Part of the HTTP header from Wireshark logs:</p>

<blockquote>
  <p>POST /PFDemo/MotionDetectAttachment.aspx?cameraID=1 HTTP/1.0<br>
  Host: {correct host IP}<br>
  Content-Type: video/mp4<br>
  Content-Length: 158689<br>
  Authorization: Basic<br>
  Connection:close<br>
  X-EventInfo: motion,71,md_window3</p>
</blockquote>

<p>(the X-EventInfo values are from the camera)</p>
