• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sending post parameters to a servlet

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"GET" is the default request method for an HttpConnection object. So you'll need to change it like this:



Hopefully, that'll do the trick!

- Jeff
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ususally attach it to the URL string with ? and &

like

www.somesite.com/someServet?action=someAction&payload=somePayload

Mark
 
Jeff Jetton
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mark Spritzler:
I ususally attach it to the URL string with ? and &

like

www.somesite.com/someServet?action=someAction&payload=somePayload



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


  • - Jeff
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    permaculture is largely about replacing oil with people. And one tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic