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

private void button2_Click(object sender, EventArgs e)
            byte[] buffer = new byte[100000];
            int read, total = 0;
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("");
                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?
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
[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    
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:

For H.264 Based IP Cameras:

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.

Share this answer
Try This
<httpWebRequest useUnsafeHeaderParsing="true" />
Share this answer
Member 11161737 19-Oct-14 13:07pm    
where to write this code? i'am new in this project thx
Share this answer
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

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