• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

POST parameter coming in null

 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm hoping I've a small mistake I'm not seeing.

In this simple demo, the POST parameter is coming in null. In other words, it ain't being received by the Servlet.

from Midletfrom ServletAnybody see what I'm doing wrong?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could be completely wrong, as I usually am.

But you are sending the taskid as the content, not as a parameter.

Usually what I do is add it to the URL string as in

www.website.com/servlet?taskId=1

and pass that string to the Connector.open method.

Something along those lines and that would work. I don't have actual sample code anymore to show if I remembered correctly or not.

Mark
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you answered yourself correct.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark, I believe you were correct.

From the documentation of HttpConnection, I thought I understood that the request parameters had to be sent before an output stream was established, but I couldn't figure out another mechanism for sending request parameters. I'd not realized that POST request parameters could be sent as part of the URL, as GET request parameters are sent. (I was following an example from a book for making a POST request, which also didn't work for me. Who knew you can't believe everything you read?)

Thanks for the lesson.
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
(I was following an example from a book for making a POST request, which also didn't work for me. Who knew you can't believe everything you read?)


Hope this is not my book that you were talking about!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wasn't.
 
manoj pillai
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is perfectly valid. The missing POST parameter is due to a known issue (a perf optimization infact!) where in the Transfer-encoding:chunked HTTP header gets set automatically when you do an out.flush(). You basically loose the POST data if the webserver is unable to recognise a chunked request properly.

So just comment out the out.flush() from your code and see the magic!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic