Hello All,

I have a very simple doPost method that reads the body of a POST request. Seems to work fine on 6.0.14 but consistently fails to read the body correctly in 6.0.16. Can someone help me with what's wrong here?

Thanks!

-- john

 protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

     // read POST body
     StringBuffer sb = new StringBuffer();
     try {
        BufferedReader reader = request.getReader();
        String inputLine;
        while ((inputLine = reader.readLine()) != null) {
           sb.append(inputLine);
        }
     } catch (IOException e) {
        throw new IllegalStateException("Error reading request body");
     }
     String content = sb.toString();
     log.debug("read "+content.length()+" characters from POST body");
     if (content.length() != request.getContentLength()) {
log.warn("Expected content length of "+request.getContentLength()+" but only read "+content.length()+" characters");
     }
//write out read content to file PrintStream os = new PrintStream(new FileOutputStream("/tmp/post_body.txt"));
     os.println(content);
     os.close();

     PrintWriter out = response.getWriter();
     response.setContentType("text/plain");
     out.println("Content Type: " + request.getContentType());
out.println("POST body contained " + request.getContentLength() + " characters"); out.println("read " + content.length() + " characters from POST body");
     out.flush();
     out.close();
  }

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to