Luís Tavares Luís Tavares - 4 months ago 30
HTTP Question

JavaME - HTTP Get - Send Values to Website

I'm building a project in which I want a method to make a simple http GET request in order to send two variables to an website via URL.
In a normal java project I would likely use or apache and solve the issue in a matter of minutes. In JavaME, due to my lack of experience I'm not really being able to fulfill the task.

Basically what I want to do is having an url like

being able to do a get request in order to send those variables via URL.

Any tips?



Here's an example of how you could do something like that.

HttpConnection connection = null;
InputStream inputstream = null;
String url = null;
StringBuffer dataReceived = null;

    url = "";
    dataReceived = new StringBuffer();

    try {
        connection = (HttpConnection);
        connection.setRequestProperty("Content-Type", "text/plain");
        connection.setRequestProperty("Connection", "close");

        if (connection.getResponseCode() == HttpConnection.HTTP_OK) {
            inputstream = connection.openInputStream();
            int ch;
            while ((ch = != -1 ) {
                dataReceived.append((char) ch);

        } else {
            // Connection not ok
    } catch (Exception e) {
      // Something went wrong
    } finally {
        if (inputstream != null) {
            try {
            } catch (Exception e) {
        if (connection != null) {
            try {
            } catch (Exception e) {

Note: I didn't test this specific code. I just edited some code I had lying around from a previous project of mine, so you may need to fix a few errors.