Web request in C++

Hi,

I am writing program in C#. But I have problem with .Net. So I need some code in C++.

My problem:
I need to send web request to my IP camera and receive jpeg image. I can get image only if I send by Http protocol version 0.0
But .Net supports only Http protocol version 1.0 and 1.1. (by these protokols version responce from ip camera has content type text/html, but by protokol 0.0 responce content type image/jpeg)

Please, can anybody write to me code in C++(not .Net) equivalent to this C# code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
 
namespace somenamespace
{
    static public class IpCameraRequest
    {
        static public bool GetBitmapFromHttpRequest(String link, String filePath)
        {
 
            // Create web request
            // e.g for "http:// 111.11.11.11 /liveimg.cgi"
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link);
 
            // set login and password 
            string login = "admin";
            string password = "admin";
            request.Credentials = new NetworkCredential(login, password);
 
            // set version of http protocol
            // I need version 0.0, but .Net dont support this version !!!!!! 
            request.ProtocolVersion = HttpVersion.Version10;
 
            // get web response
            HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
 
            // get stream from response
            StreamReader responseStream = new StreamReader(webResponse.GetResponseStream());
            Stream stream = responseStream.BaseStream;
 
            // get string representation from stream  (not important)
            string stringResponseStream = responseStream.ReadToEnd();
 
            // try to get bitmap from stream and save to file
            try
            {
                Bitmap bmp = (Bitmap)Bitmap.FromStream(stream);
                bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                return true;
            }
            catch //(Exception ex)
            {
                //MessageBox.Show("error " + ex.Message);
                return false;
            }
        }
    }
}
 


Thanks in advance.
Last edited on
There was never a HTTP 0.0, you probably mean version HTTP 0.9. The first defined version was HTTP 1.0 in RFC 1945. HTTP 0.9 is an incomplete implementation of HTTP 1.0, a retro version.

If you don't send the version number, 0.9 is assumed.
kbw, Thanks for answer.

The link of JpegStream of IP camera is
http://xxx.xx.xx.xxx/liveimg.cgi
Browser simultaneously shows jpeg image.

But in code I qet bytes and they decoded to simple html file.

when I use Socket class and send to socket

GET /liveimg.cgi HTTP/0.0

I receive image bytes with header ... content-type = image/jpeg ...

and if I send to Socket class

GET /liveimg.cgi HTTP/1.0
or
GET /liveimg.cgi HTTP/1.1

I receive html bytes with header ... content-type = html/text ...

By telnet same situation.

What did you think about this situation?
Can you write C++ equivalent of appointed C# code?
A 1.1 request has more fields than you're specifying. You really need to read up on the protocol or look at what a 1.1 compliant browser sends or both. You can't just poke about and hope for the best.

Like I said, there's no 0.0, you should omit the version for 0.9. That's probably what the camera is using when you send 0.0. If that's what works, then you could stick with that.
Topic archived. No new replies allowed.