By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,440 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,440 IT Pros & Developers. It's quick & easy.

HttpWebRequest Exception on HTTP/1.0 204 No Content

P: n/a
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.ToStrin g());
//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.Exceptio n, "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

Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

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,
"su*******@gmail.com" wrote:
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.ToStrin g());
//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.Exceptio n, "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

Nov 22 '05 #2

P: n/a
As written in my post I'm coding a C# Application.

Anyway thanks for replying.

Nov 22 '05 #3

P: n/a
C# is a language. wich can be used in a web environment and/or windows.

"su*******@gmail.com" wrote:
As written in my post I'm coding a C# Application.

Anyway thanks for replying.

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.