//I figured out the problem. Example case: POST Request from a webpage
with 2 text fields (userEmail = '[email protected]', and favCar =
'corvette')
//If I use
String email = req.getParameter("userEmail")
//and then try to get the whole body of the POST
InputStream inputStream = req.getInputStream();
if (inputStream != null) {
byte[] body = new byte[inputStream.available()];
inputStream.read(body);
String body = new String(body);
}
//body = ""
//but if I comment out the use of ANY getParameter Call, I get body
fine.
//Also, the reverse also holds true
//if you get the body using the InputStream, then try to use
getParameter
//then all of your getParameters will return null
//I don't know if this is by design or a bug because I'm not
experienced Java Programmer
-Bourke
On Nov 23, 5:50 pm, "Ikai L (Google)" <[email protected]> wrote:
> What are you posting? This code works for me:
>
> public class TestPostServlet extends HttpServlet {
>
> protected void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> InputStream in = request.getInputStream();
>
> int size = in.available();
> byte[] body = new byte[size];
> int status = in.read(body);
> in.close();
>
> response.getWriter().println("Status of read: " + status + " Size: "
> + size);
> response.getWriter().println("Got your post: " + new String(body));
>
> }
>
> }
>
> What mechanism are you using to POST to your application? Is it a browser
> form or a custom client?
>
> On Sat, Nov 21, 2009 at 12:37 PM, Bourke Floyd IV <[email protected]> wrote:
>
>
>
>
>
> > //This was working before I overhauled the authentication of my app
> > //I'm trying to store the body of a Http POST as Text, I also plan on
> > doing a Blob version
> > //The maxLength is returning the correct size, but the read is
> > returning -1 instead of properly
> > //updating the body byte array
>
> > //...
>
> > InputStream httpIn = req.getInputStream();
> > byte[] body = new byte[httpIn.available()];
> > httpIn.read(body);
>
> > Text myPostBody = new Text(new String(body)); //wasteful maybe? but
> > should work
>
> > //...
>
> > //My old code was roughly the same
>
> > //...
>
> > int maxLength = req.getContentLength();
> > byte[] body = new byte[maxLength];
>
> > InputStream httpIn = req.getInputStream();
> > httpIn.read(body, 0, maxLength);
>
> > String myPostBody = new String(body); //wasteful maybe? but should
> > work
>
> > //...
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Google App Engine for Java" group.
> > To post to this group, send email to
> > [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<google-appengine-java%2B
> > [email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-appengine-java?hl=.
>
> --
> Ikai Lan
> Developer Programs Engineer, Google App Engine
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.