Click here to Skip to main content
15,558,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

C#
private void button2_Click(object sender, EventArgs e)
        {
            byte[] buffer = new byte[100000];
            int read, total = 0;
            try 
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://192.168.1.253/nphMotionJpeg?Resolution=320x240&Quality=Standard");
                req.Method = "POST";
                //req.Timeout = 500;
                NetworkCredential cred = new NetworkCredential("Administrator", "admintdx");
                req.Credentials = cred;
                WebResponse resp = req.GetResponse();
                // get response stream

                Stream stream = resp.GetResponseStream();
                // read data from stream

                while ((read = stream.Read(buffer, total, 1000)) != 0)
                {
                    total += read;
                }
                // get bitmap

                Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, total));
                pictureBox1.Image = bmp;

            }
            catch (Exception ex)
            {
                MessageBox.Show("Grab Error:" + ex, "Error!!");
            }


        }


I am working on a project sample to capture image from IP camera, but I got this error: "The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF". Is there any other option to read the response of my scrape URL. Please let me know how can it be possible... Could someone help?
Posted
Comments
bbirajdar 12-Jan-12 8:43am    
what is a "IP" camera?
jiojo 5-May-12 5:20am    
could you please post the correct code or tell the class for other function please
its urgent !!!

 
Share this answer
 
Comments
[no name] 17-Oct-14 11:48am    
You have my vote of 5, good find Javed.
Jαved 23-Oct-14 3:22am    
Thanks CodingK :)
[no name] 23-Oct-14 6:46am    
You're most welcome, let me know if i can be of further help. :)
Jαved 28-Oct-14 11:17am    
Sure.
Here are two examples, both with live demos. Both are free. Both are HTML/JavaScript based, but they still can be used for reference.

For MJPEG Based IP Cameras: http://foscam.us/forum/free-generic-browser-interface-for-foscam-ip-mjpeg-cameras-t2522.html

For H.264 Based IP Cameras: http://foscam.us/forum/free-generic-browser-interface-for-foscam-ip-h-264-cameras-t2686.html

Note: The above examples, work with ANY Internet browser capable device, that is running on ANY Operating System, using ANY browser. From Computers to Tablets to Phones and even some TVs.

There are 10 Live Demos, one of which includes using your own camera(s) with the example, without needing to download/install anything first.

It's also possible to embed the above Interfaces in the actual Web UI camera firmware, as well, as to not require a web host/sever to serve them. Using your camera as a web host/mini-website.

Don
 
Share this answer
 
v3
Try This
XML
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
 
Share this answer
 
Comments
Member 11161737 19-Oct-14 13:07pm    
where to write this code? i'am new in this project thx
 
Share this answer
 
Comments
Richard MacCutchan 25-Oct-15 10:28am    
This question was posted almost 4 years ago. Do you think the OP is still waiting?
George I. Birbilis 16-Nov-15 16:24pm    
welcome to Google - others (like me) come across this article while searching for the same subject
George I. Birbilis 16-Nov-15 16:25pm    
btw, I ended up clearing and advancing that code a lot and now supporting both MJPEG and HD models of Foscam IP Camera. Published at http://FoscamController.codeplex.com

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900