×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    8

    Could not solved the post problem.

    Hi,
    I've read most of the articles about post problem but i could not find any solution for my problem. The code at the below works on Non-Nokia physical devices (Sony-EricssonT616..) and Nokia emulators without a problem. But on physical Nokia device (i've tried on 1100,3100) it did not work. Does anyone has any idea. I am stuck, help me out please.!

    c = (HttpConnection)Connector.open(url, Connector.READ_WRITE);
    c.setRequestMethod(HttpConnection.POST);
    c.setRequestProperty("CONTENT-TYPE","application/x-www-form-urlencoded");
    c.setRequestProperty("Accept","application/octet-stream");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-US");
    os = c.openOutputStream();
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.write(postmsg[i]);
    }
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    }

    thanks for your help..
    Regards..

  2. #2
    Registered User
    Join Date
    Jan 2004
    Posts
    25
    u should set another more request property 'Content-Length', which specified the length of the content you want to post !

    good luck...

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    8
    I've tried that too. It did not work.. here is the code;
    try {
    c = (HttpConnection)Connector.open("http://www.turkonline.com/gw/tomi/v1/");
    c.setRequestMethod(HttpConnection.POST);
    c.setRequestProperty("CONTENT-TYPE","application/x-www-form-urlencoded");
    c.setRequestProperty("Accept","application/octet-stream");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-US");
    c.setRequestProperty("Content-Length", Integer.toString(str.length()));
    os = c.openOutputStream();
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.write(postmsg[i]);
    }

    // also it works with these...
    //os.flush();
    //os.close();
    if (c.getResponseCode() == HttpConnection.HTTP_OK) {
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    //System.err.println("----> " + b);
    }

    I beleive i added eveything as setRequestProperty.. And it does not work.. Any idea?! or Help? Please..

  4. #4
    Registered User
    Join Date
    Jan 2004
    Posts
    25
    In my app it worked well on emulator as well as on physical nokia phone. I didn't add any request property except 'Content-length', and I post the content CHAR by CHAR, NOT BYTE by BYTE; I don't know what's the content you want to post like, if the content includes non-ascii character, there must be difference between the two ways, maybe you should encode the content you want to post firstly.

    lastly, you can add some trace statement in you app to see it terminated in which statement.

    wish you good luck...

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    8
    Thank you so much for your help. On the other hand I would like to ask for one more favor. Can you send your POST function to me with char and char post method.. Because I am loosing my mind, (maybe i've already lost

    Also I've tried on 6600 and it worked. It is still not working on 1100 and 3100 phones.

    So if you can send me your POST function I can compare with my code and figure the problem out.

    Thanks in advance..

  6. #6
    Registered User
    Join Date
    Jan 2004
    Posts
    25
    here is part of my program:

    String strPara = "abc"; // post content
    int len = strPara.length();
    http = (HttpConnection) Connector.open(url);
    http.setRequestMethod(HttpConnection.POST);
    http.setRequestProperty("Content-Length", Integer.toString(len));
    os = http.openOutputStream();
    for(int i = 0; i < len; i++) {
    os.write(strPara.charAt(i));
    }

    others is useless to you...

    another hint, maybe you should specify the full url, like this:
    http://...../index.jsp

    good luck.

Posting Permissions

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