473,473 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5723

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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.