Does anyone know what is wrong with this code or why I might be experiencing
this behavior?
I have a Java application that submits HTTP POST requests to a servlet (with
content in the body of the request). I am using the java.net package. My
system worked fine with Tomcat 4.1.18: the servlet was invoked with a POST
request and it could read the content of the request using an InputStream.
But when I deploy my servlet in Tomcat 5 it no longer is invoked as a POST,
but rather a GET (the doGet method is called instead of the doPost, which is
called when deployed in Tomcat 4). The Serlvet therefore does not get the
body of the request (the Servlet's InputStream has no content).
My client code looks like this:
String request = "test";
java.net.URL netUrl = new java.net.URL(http://localhost:8080/myservlet);
connection = (HttpURLConnection) netUrl.openConnection();
connection.setRequestMethod( "POST" );
connection.setRequestProperty("Content-Length", "" +
Integer.toString(request.getBytes().length));
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream out = new DataOutputStream( connection.getOutputStream() );
out.writeBytes( request );
out.flush();
out.close();
BufferedReader reader = new BufferedReader( new InputStreamReader(
connection.getInputStream() ) );
String response = reader.readLine();
while( null != response )
{
System.out.println( response );
response = reader.readLine();
}
Does anyone have any ideas?
Thank you,
Steve