Remote server returns (500) Internal Server Error,when posting xml

G

Guest

I am posting xml to a server and get the above error returned. The client
code is listed below, it works until say a "<" character is put in XmlData.
On the server page I try to pick up the XmlData with:
Response.Write(Request.Form["XMLData"]);

Client side code:

ASCIIEncoding encoding = new ASCIIEncoding();
string XmlString = "<TEST";
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";


byte [] body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));
IoHttp.ContentLength = body.Length;


try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);


HttpWebResponse loWebResponse = (HttpWebResponse) IoHttp.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();

}
catch (WebException webexception)
{

}

catch
{

}
finally
{
if (requestStream != null) requestStream.Close();
}




Can anyone see the problem with this?

Thanks
Danny
 
J

Joerg Jooss

Danny said:
I am posting xml to a server and get the above error returned. The
client code is listed below, it works until say a "<" character is
put in XmlData. On the server page I try to pick up the XmlData
with: Response.Write(Request.Form["XMLData"]);

ASP.NET does not allow form data containing certain characters used in
injection attacks by default . You can disable this feature using the
page directive ValidateRequest="false", but a better approach is to
post the XML "as is", and not as form data. See
http://tinyurl.com/b8al3 for a sample.

On the server-side, read the XML directly from Request.InputStream.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top