简体   繁体   中英

How to save video/MP4 from POST body in C#

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:

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

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.

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.

Camera log sample:

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

Part of the HTTP header from Wireshark logs:

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

(the X-EventInfo values are from the camera)

Have you changed the defaults for maxRequestLength and executionTimeout? Even if you have you may still have issues.

Jon Galloway wrote an excellent article on this.

maxAllowedContentLength also comes into play. Answers to this SO question may help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM