开发者

Problem reading Java Servlet input stream in Google App Engine

开发者 https://www.devze.com 2023-04-05 02:53 出处:网络
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

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:

  1. getReader throws a java.lang.IllegalStateException (see this)
  2. getInputStream returns a valid input stream, but calling read() on that input stream returns -1 (see this).
开发者_Python百科

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消