473,508 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Receiving xml as a byte array problem


I am working on a project in which a number of client applications will be
posting xml documents as a byte array to an ASP.NET page on our web server. I
am trying to simulate the process and run into problems.

Sending code:

ASCIIEncoding encoding = new ASCIIEncoding();

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("<Data>Test Data</Data>");

loHttp.Method="POST";
loHttp.ContentType = "application/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;

Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer,0,lbPostBuffer.Lengt h);
loPostData.Close();

HttpWebResponse loWebResponse = (HttpWebResponse)
loHttp.GetResponse();

Encoding enc = System.Text.Encoding.GetEncoding(1252);

StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream());

string lcHtml = loResponseStream.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.Close();
loResponseStream.Close();

Receiving code:
Stream str = Request.InputStream;
int strLen = (int)str.Length;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0,strLen);
string strmContents = System.Text.Encoding.ASCII.GetString(bArr,
0, bytes);
Response.Write (strmContents);
The above code will work with XMLData=xyz. But when “<” or “>” is in the
string as above, an error is returned from the receiving page:
The remote server returned an error: (500) Internal Server Error

If the following line is commented out, it works:
loHttp.ContentType = "application/x-www-form-urlencoded";

When it works with the above line commented out, the result displayed is:
XMLData=%3cData%3eTest+Data%3c%2fData%3e

If I use:
string strXMLData = System.Text.Encoding.ASCII.GetString(bArr);
strXMLData = HttpUtility.UrlDecode(strXMLData);
Response.Write (strXMLData);

The result I get is: XMLData=Test Data
I need the end result to be <Data>Test Data</Data>"

Where am I going wrong?

Thanks for any help

Dec 12 '05 #1
0 1326

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7785
by: Stephan Steiner | last post by:
Hi I have a small program listening to UDP broadcast datagrams that are periodically sent out. It will stop listening for a certain period if either a sufficient number of packets has been...
2
4737
by: tantiboh | last post by:
I'm not a new programmer, but this one's got me stymied; hopefully it's a fairly trivial problem. I'm using a socket connection to receive communication from a server. Normally, the entire message...
8
10684
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
0
1310
by: Zahid | last post by:
Hi, Im a little confused with sending and receiving data using UDP comms. Im writing an app that sends and recieves data (a byte array) using the UDP protocol. The data I send is 36 bytes long...
5
1814
by: Danny | last post by:
I am working on a project in which a number of client applications will be posting xml documents as a byte array to an ASP.NET page on our web server. I am trying to simulate the process and run...
7
1615
by: marfi95 | last post by:
Hi all, I'm stuck and hope someone out there knows how to get around this. I have to interface with a 3rd party vendor win32 dll and on one of their calls, they are returning a bunch of data...
14
2488
by: Ronodev.Sen | last post by:
i have a C# program that is sending data in a byte array through a socket. the VC++ application server receives data in teh following format.... typedef struct advice { header sHdr; char ...
7
3165
by: darthghandi | last post by:
I am having mixed results with asynchronous socket receives. Sometimes I get the right information back from the buffer, other times I get some of the data that should be in the buffer printed out...
0
3548
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
0
7120
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
7323
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,...
1
7039
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
5626
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 projectplanning, coding, testing,...
1
5050
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
4706
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
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
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 ...
1
763
muto222
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.