HttpWebRequest Exception on HTTP/1.0 204 No Content

S

superseed

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.Create(m_PtzUri.ToString());
//construct header
l_Req.Headers.Clear();
l_Req.KeepAlive = false;
l_Req.Timeout = 2000;
l_Req.Method = "POST"; // POST or GET
string sMessage = _CommandLine;
l_Req.ContentLength = sMessage.Length;

//convert login:password to Base64 string
Encoding asciiEncoding = Encoding.ASCII;
byte[] byteArray = new byte[m_PtzUri.UserInfo.Length];
byteArray = asciiEncoding.GetBytes(m_PtzUri.UserInfo);

//Camera are using Authorization Basic
l_Req.Headers.Add("Authorization", "Basic " +
Convert.ToBase64String(byteArray));
//standard url encode
l_Req.ContentType = "application/x-www-form-urlencoded";

//write the post in the stream
Stream l_StreamReq = l_Req.GetRequestStream();
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 = (HttpWebResponse)l_Req.GetResponse();

//read the answer
if(l_Resp.StatusCode == HttpStatusCode.NoContent)
LogViewer.WriteLine(LogViewer.MessageType.Info, "Send",
_CommandLine);
l_StreamReq.Close();
}
catch(WebException e)
{
LogViewer.WriteLine(LogViewer.MessageType.Exception, "WebException",
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 cm9vdDpsdHM1Y2FtZQ==
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 = (HttpWebResponse)l_Req.GetResponse();


Anyone can help me on this ? Thanks.

Christophe
 
G

Guest

no need to use that class.

just use javascript http request to send a header value to the asp.net page
and do a request header in the asp.net page. to send back the value just to a
response.write in the asp.net page and catch this in the javascript page.

I have used the http request like this ;-)

greets,


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.Create(m_PtzUri.ToString());
//construct header
l_Req.Headers.Clear();
l_Req.KeepAlive = false;
l_Req.Timeout = 2000;
l_Req.Method = "POST"; // POST or GET
string sMessage = _CommandLine;
l_Req.ContentLength = sMessage.Length;

//convert login:password to Base64 string
Encoding asciiEncoding = Encoding.ASCII;
byte[] byteArray = new byte[m_PtzUri.UserInfo.Length];
byteArray = asciiEncoding.GetBytes(m_PtzUri.UserInfo);

//Camera are using Authorization Basic
l_Req.Headers.Add("Authorization", "Basic " +
Convert.ToBase64String(byteArray));
//standard url encode
l_Req.ContentType = "application/x-www-form-urlencoded";

//write the post in the stream
Stream l_StreamReq = l_Req.GetRequestStream();
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 = (HttpWebResponse)l_Req.GetResponse();

//read the answer
if(l_Resp.StatusCode == HttpStatusCode.NoContent)
LogViewer.WriteLine(LogViewer.MessageType.Info, "Send",
_CommandLine);
l_StreamReq.Close();
}
catch(WebException e)
{
LogViewer.WriteLine(LogViewer.MessageType.Exception, "WebException",
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 cm9vdDpsdHM1Y2FtZQ==
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 = (HttpWebResponse)l_Req.GetResponse();


Anyone can help me on this ? Thanks.

Christophe
 
S

superseed

As written in my post I'm coding a C# Application.

Anyway thanks for replying.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top