Receiving xml problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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.Length);
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


.



Relevant Pages

  • Re: encoding nightmare
    ... > receiving page: The remote server returned an error: Internal ... > Server Error ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Receiving xml problem
    ... throws an error if a "<" is found in the form data. ... > The remote server returned an error: ...
    (microsoft.public.dotnet.framework.aspnet)
  • encoding nightmare
    ... posting xml documents as a byte array to an ASP.NET page on our web server. ... Sending code: ... Receiving code: ... The remote server returned an error: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Receiving xml as a byte array problem
    ... posting xml documents as a byte array to an ASP.NET page on our web server. ... Sending code: ... Receiving code: ... The remote server returned an error: ...
    (microsoft.public.dotnet.general)
  • Re: send 1 dim array as hidden type via form
    ... I don't think HTML forms can have arrays as values. ... This should send the 3 values through as an array called $redarray and you ... then need to strip each part back out again in your receiving code. ... > Sending code as follow: ...
    (php.general)