webrequest problem

Jul 19 2005 11:01 AM
I'm trying to post a string of xml to another site and I've set up a test script on my own machine to recieve and parse the xml and return a value.  When I run that page by itself and feed it some xml, it works fine.  But, when I try to call it with the webrequest object, I get an internal server error.  Can anyone see what I'm doing wrong here?  I've never used this class before so I'm not really sure if I'm doing everything I'm supposed to.  Thanks.  Oh, and it errors on the line that says WebResponse myWebResponse = myRequest.GetResponse();

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/test.asp");

myRequest.Method="POST";

myRequest.ContentType = "application/x-www-form-urlencoded";

ASCIIEncoding encoder = new ASCIIEncoding();

// Convert the string into a byte array.

byte[] xmlBytes = encoder.GetBytes("xmlData="+xDoc.InnerXml);

myRequest.ContentLength = xmlBytes.Length;

Stream newStream=myRequest.GetRequestStream();

newStream.Write(xmlBytes,0,xmlBytes.Length);

newStream.Close();

// Return the response.

WebResponse myWebResponse = myRequest.GetResponse();

// Obtain a 'Stream' object associated with the response object.

Stream ReceiveStream = myWebResponse.GetResponseStream();

Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

// Pipe the stream to a higher level stream reader with the required encoding format.

StreamReader readStream = new StreamReader( ReceiveStream, encode );

response = readStream.ReadToEnd();

readStream.Close(); readStream = null;

myWebResponse.Close();