473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

HttpWebRequest Exception on HTTP/1.0 204 No Content

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
3 5714

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
As written in my post I'm coding a C# Application.

Anyway thanks for replying.

Nov 22 '05 #3
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
3
by: superseed | last post by:
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 : ...
3
by: ME | last post by:
Hi; I am getting "Unhandled Exception: System.Net.WebException: The remote server returned an erro r: (401) Unauthorized." when I am trying to get a page via post. Code follows...
1
by: ATS | last post by:
PRB - HttpWebRequest does not work with CGI websites and/or RAW data Please help, I'm trying to make a web deploying UserControl that gets RAW binary data that is dynamically created from a...
1
by: iana_kosio | last post by:
Hi, I am using HttpWebRequest class to communicate with remote server. In some cases the server would return 5xx status code which results in HttpWebRequest object throwing an exception. I,...
0
by: boxboy | last post by:
Hi, I'm writing a console application and am having a problem with HttpWebRequest when posting data to a webserver. A "System.Net.WebException: The server committed a protocol violation" is always...
1
by: mfreeman | last post by:
I have a VB.NET 2005 Windows application that worked fine when I ran it a month ago, and now it is throwing an exception ("The remote server returned an error: (500) Internal Server Error.") and I...
4
by: Natalia | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great...
0
by: BillE | last post by:
VS2005 VB.net I'm using the HTTPWebRequest class to connect to a web site with SSL. I first manually connected to the site and installed the certificate on my computer, and then use the...
1
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.