×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Dec 2003
    Posts
    109

    J2ME - passing variables to server-side script

    I am trying to write a MIDlet, that collects user information and sends it to a server via URL.

    On the server side, I have a script (namely PHP - I just feel more comfortable with it) that takes variables inlcuded in the requested URL and inserts them into a database.

    This works. However, URLs get quite large, AND, most importantly, if any user-entered values have spaces (and they most certainly will), the app will not work - obviously, since URLs cannot have spaces in them.

    So, my question is whether it is possible to pass variables to a server-side script another way than with URL.

    Alternavely, is there a way to parse strings from user input (TextField) and substitute any spaces?

    Thank you for the input.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    Netherlands
    Posts
    18
    You are able to transfer the information by POSTing it. Take a look at http://developers.sun.com/techtopics...cles/servlets/ or code.http://developers.sun.com/techtopics...ostMidlet.java for example MIDlet s

  3. #3
    Regular Contributor
    Join Date
    Dec 2003
    Posts
    109
    Thank you for the post. I have reviewed the information but it has not answered my question, since the tutorials did not deal with exactly the same issue. I tried to project the information onto my situation but with no success up to this point.

    What I am trying to do is collect values with Java application and post them to the PHP script. Previously, I collected values with html and/or wml forms and passed them on with post method to the script.

    However, opening an http connection, setting request method to POST, and sending string with variable names and values with OutputStream did not produce the same effect.

    Am I missing something or am I trying to do something impossible? Thanks again.

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    You should url-encode your data, so instead of sending blank spaces you would be sending %20 (that 20 is 32 in hex, and 32 is the ascii value for space), and the same for any other characters that can be illegal in a url. Setting the content-type header (setRequestProperty()) to x-www-form-urlencoded could also help.
    Check out the Http 1.1 spec (specially section 14), for more info on that.

    shmoove

  5. #5
    Regular Contributor
    Join Date
    Dec 2003
    Posts
    109
    Thank you for the tip. The problem with this solution is that it is the user who enters the information. When making a similar operation in PHP scripts, I was using an rawurlencode() function that substituted any blank spaces with %20. Is there a similar function in MIDP?

  6. #6
    Regular Contributor
    Join Date
    Dec 2003
    Posts
    109
    Ok, got it. Thanks a bunch (again!) for the help. If anyone else is looking for a comprehensive example here is a link: http://developers.sun.com/techtopics...les/socketRMI/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×