I have a small .NET class that I'm using to POST an XML
string to my
Java Servlet.
The Servlet writes the XML file to disk from the POSTed string data it gets.
I've noticed that running the .NET "EXE" doesn't always result in an XML file being created, though most of the time, it does work.
For those times, often the first time I run it, the
Tomcat error log says that the Servlet has an IO Exception and with:
e.getCause="null", and
e.getMessage="connection reset".
Not sure what's causing this.
Any ideas?
-- Mike
The .NET class is simple and similar to this:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://myServletAddressHere");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = // call to .NET Web Service goes here to get XML String
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
(
http://msdn.microsoft.com/en-us/library/debx8sh9.aspx)