2

I have made one Application which requires internet connection so that I can display some data in my app.

But when I test my that app in Nokia c1-01 it can't get data from my server and at the same time if I check my app in any other device they are easily connected with internet and I can see my app.

Here is my code:

    HttpConnection httpConn = null;

    InputStream is = null;
    OutputStream os = null;
    StringBuffer sb = new StringBuffer();

    try {
        // Open an HTTP Connection object
        httpConn = (HttpConnection) Connector.open(url);
        // Setup HTTP Request to POST
        httpConn.setRequestMethod(HttpConnection.POST);

        httpConn.setRequestProperty("User-Agent",
                "Profile/MIDP-2.0 Confirguration/CLDC-1.1");
        httpConn.setRequestProperty("Accept_Language", "en-US");
        //Content-Type is must to pass parameters in POST Request
        httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        os = httpConn.openOutputStream();



        os.write(params.getBytes());

        /**Caution: os.flush() is controversial. It may create unexpected behavior
        on certain mobile devices. Try it out for your mobile device **/
        //os.flush();
        // Read Response from the Server
        //StringBuffer sb = new StringBuffer();
        is = httpConn.openDataInputStream();
        int chr;
        while ((chr = is.read()) != -1) {
            sb.append((char) chr);
        }
    } finally {
        if (is != null) {
            is.close();
        }
        if (os != null) {
            os.close();
        }
        if (httpConn != null) {
            httpConn.close();
        }
    }

What I have to change in my code so that it can run on my Nokia C1-01?

gnat
  • 6,213
  • 108
  • 53
  • 73
dhrut
  • 147
  • 1
  • 9

1 Answers1

0

Two things comes to mind.

The first one is trivial, and has to do with Internet settings on the phone. I don't know the Nokia C1 specifically, but I know that many devices have an Internet setting for the device + another Internet setting for Java. Make sure that the Internet setting for Java is correct. Just because you can use the browser on the phone, doesn't mean that Internet connection works for Java MIDlets.

The second thing you can look into, has to do with the Content-Type property.

I had this issue when I was developing a game that retrived and sent highscores to my webserver, via PHP on the server. I found it rather weird that it worked fine on most our test-phones, while a few had issues.

Outputting the data the phone received back revealed a 404 reply (or something similar, it's been a while).

After consulting another JavaME developer, I learned this:

Some devices send specific instructions to the webserver: "Hello. Gimme some data of type text/plain from data.php please". If data.php contains a header('Content-type: text/plain'), then all is fine. If not, then the server replies: "Sorry mate, I don't have any text/plain stuff at that address".

This only happens on some devices, because only some devices send that specific a request.

So, whatever Content-Type you define in your setRequestProperty() in the JavaME part, must be the same in your server-side script.

Hope one of those two things helps. :-)

mr_lou
  • 1,910
  • 2
  • 14
  • 26
  • Thank you so much for your answer.but I have used code shown in below to get data from server through php: so can you tell me what I have to add in my php page?. – dhrut Oct 20 '12 at 10:56