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:
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
{
staticpublicclass IpCameraRequest
{
staticpublicbool 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);
returntrue;
}
catch //(Exception ex)
{
//MessageBox.Show("error " + ex.Message);
returnfalse;
}
}
}
}
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.
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.