Click here to Skip to main content
Rate this: bad
good
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 18:52pm
rudiank756
Comments
B Birajdar at 12-Jan-12 8:43am
   
what is a "IP" camera?
jiojo at 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 at 17-Oct-14 11:48am
   
You have my vote of 5, good find Javed.
Jαved at 23-Oct-14 3:22am
   
Thanks CodingK :)
CodingK at 23-Oct-14 6:46am
   
You're most welcome, let me know if i can be of further help. :)
Jαved at 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 at 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 at 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 at 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 at 22-Oct-14 8:58am
   
Either respond to one of the other solutions or post your own question
CodingK at 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.

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

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 17 Oct 2014
Copyright © CodeProject, 1999-2014
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