G
Guest
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
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