Problem reading Java Servlet input stream in Google App Engine
I'm building something using Google App Engine and I'm trying to create a java Servlet that reads the raw POST data and does something with it. According to the servlet documentation, this should be possible using either the getReader() method or the getInputStream() method. However it appears that somehow, at least with the App Engine development server that runs locally on my dev box, getInputStream() has already been called before the doPost method is even entered.
My evidence for asserting this is as follows:
- getReader throws a java.lang.IllegalStateException (see this)
- getInputStream returns a valid input stream, but calling read() on that input stream returns -1 (see this).
I checked and I am not calling getParameter() before I call getInputStream. getInputStream() is the FIRST thing I call in the body of the doPost method.
What is wrong here?
Per this link from google app engine issue tracker :
That is because the content type was sent as "application/x-www-form-urlencoded". In that case the stream is read and mapped as key value pair so that you can access the data as req.getParameter("ParameterName") and for the same reason stream is empty. We will be able to access the req.getinputStream() when the content-type is sent as "application/octet-stream".
精彩评论