I'm writing a game that that can transmit a high score to a servlet running in Tomcat. But I can't seem to figure out how to get the midlet to transmit a parameter using the post method.
I have a simple html form set up to test the server which sends two params by POST, the first called 'action' and the second called 'payload'. (The servlet uses it's request.getParameter("action") or ("payload") in it's doPost() to retrieve the parameters). This works fine, but how can I send params from midlet in a way similar to the html form?
I've tried writing 'myHttpConnection.setRequestProperty("action", "some-action")' in the midlet and then 'myOutputStream.flush()' when I've set properties, but the server doesn't seem to be getting anything.
I've also tried setting the content-length property to "x-www-form-urlencoded" but still no joy
Anyone have any ideas about how I should be sending params via post? [ April 10, 2005: Message edited by: Gar Morley ]
Yeah, but that's the "GET" method. When using POST, the url doesn't have any parameters tacked on the end of it. Instead, the parameters are send in the actual body of the http request, and are therefore invisible (usually) to the web-browsing user. Other advantages to using POST include:
Larger amounts of data possible. You're not constrained by any URL length limits that the browser or web server might have.
Non-ASCII (i.e., 7-bit) data possible.
The embedded data is not bookmarked. This is especially handy when the action does something you don't want to necessarily repeat (like purchase an item, or delete a record from a database).
If doing more than a once off remote call to save high scores, try looking at project https://mermi.dev.java.net/ (mimics rmi for midp1.0 phones). Allows you to follow principals of having remote session interface, and a client stub to that interface. Hides the underlining communcation messing with http connection.