Hi,
I'm currently coding in C# a class to control a PTZ (Pan Tilt Zoom)
Camera. To control the camera I have to send request on a CGI on it.
Something like this :
http://xxxxxx/axis-cgi/com/ptz.cgi?pan=100 (GET method) or using POST.
To do that I'm using the HttpWebRequest and HttpWebResponse class of
Microsoft .Net Framework 1.1.
Here is my code :
try
{
HttpWebRequest l_Req =
(HttpWebRequest )WebRequest.Cre ate(m_PtzUri.To String());
//construct header
l_Req.Headers.C lear();
l_Req.KeepAlive = false;
l_Req.Timeout = 2000;
l_Req.Method = "POST"; // POST or GET
string sMessage = _CommandLine;
l_Req.ContentLe ngth = sMessage.Length ;
//convert login:password to Base64 string
Encoding asciiEncoding = Encoding.ASCII;
byte[] byteArray = new byte[m_PtzUri.UserIn fo.Length];
byteArray = asciiEncoding.G etBytes(m_PtzUr i.UserInfo);
//Camera are using Authorization Basic
l_Req.Headers.A dd("Authorizati on", "Basic " +
Convert.ToBase6 4String(byteArr ay));
//standard url encode
l_Req.ContentTy pe = "applicatio n/x-www-form-urlencoded";
//write the post in the stream
Stream l_StreamReq = l_Req.GetReques tStream();
StreamWriter l_SWriter = new StreamWriter(l_ StreamReq);
l_SWriter.Write (sMessage);
l_SWriter.Flush ();
//send the request now, synchronous ! (Wait for answer)
HttpWebResponse l_Resp = (HttpWebRespons e)l_Req.GetResp onse();
//read the answer
if(l_Resp.Statu sCode == HttpStatusCode. NoContent)
LogViewer.Write Line(LogViewer. MessageType.Inf o, "Send",
_CommandLine);
l_StreamReq.Clo se();
}
catch(WebExcept ion e)
{
LogViewer.Write Line(LogViewer. MessageType.Exc eption, "WebExcepti on",
e.ToString());
return false;
}
When the command is send, the camera returns a HTTP/1.0 204 No Content
which means (RFC1945) :
204 No Content : The server has fulfilled the request but there is no
new information to send back.
Here is a ethereal capture :
[Client Request]
POST /axis-cgi/com/ptz.cgi HTTP/1.1
Authorization: Basic cm9vdDpsdHM1Y2F tZQ==
Content-Type: application/x-www-form-urlencoded
Content-Length: 6
Expect: 100-continue
Connection: Close
Host: xxxxxx
pan=0
[Server Response]
HTTP/1.0 204 No Content
So my problem is, the camera is moving, the reponse is send back as we
can see on ethereal capture. But the following line threws a TimeOut
Exception like if it didn't understand the HTTP/1.0 204 No Content :
HttpWebResponse l_Resp = (HttpWebRespons e)l_Req.GetResp onse();
Anyone can help me on this ? Thanks.
Christophe