Click here to Skip to main content
12,350,728 members (24,615 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# image
Hi everyone,

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 11-Jan-12 17:52pm
rudiank785
Comments
B Birajdar 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 !!!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
CodingK 17-Oct-14 11:48am
   
You have my vote of 5, good find Javed.
Jαved 23-Oct-14 3:22am
   
Thanks CodingK :)
CodingK 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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Try This
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
  Permalink  
Comments
Member 11161737 19-Oct-14 13:07pm
   
where to write this code? i'am new in this project thx
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hello sir ji,

I want to take photos from IP Cameras on webpage in asp.net c#.

I am getting error, when I am using this code.

Parameter is not valid.

so please help me .
  Permalink  
Comments
CHill60 17-Oct-14 10:09am
   
Using what code? If you want to respond to a post use the "have a question or comment" link next to it
Subhashkumar Yadav 22-Oct-14 8:32am
   
Hello

I m using this code

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!!");
}


}


If you know please tell me.
CHill60 22-Oct-14 8:58am
   
Either respond to one of the other solutions or post your own question
CodingK 17-Oct-14 11:50am
   
Your reply is not a solution, so please do not post questions in solutions, and post your own question and don't bump old questions.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160621.1 | Last Updated 25 Oct 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100