public JSONObject sendRequest(String address, String protocol, String postData) throws IOException, JSONException {
    HttpConnection connection = null;
    try {
      connection = (HttpConnection) Connector.open("http://" + MarketTyvikJ2ME.options.ServerPath.getString() + "/" + address);
      connection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
      connection.setRequestMethod(protocol);
      if (postData != null) {
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("Content-Length", Integer.toString(postData.length()));
        OutputStream outStream = null;
		    try {
		      outStream = connection.openOutputStream();
          outStream.write(postData.getBytes("utf-8"));
          outStream.flush();
		    } finally {
          if (outStream != null) {
            outStream.close();
          }
		    }
	    }
      int rc = connection.getResponseCode();
      if ((rc == HttpConnection.HTTP_OK) || (rc == HttpConnection.HTTP_CREATED)) {
        InputStream inStream = null;
        String response = "";
        try {
          inStream = connection.openInputStream();
          InputStreamReader inStreamReader = new InputStreamReader(inStream, "utf-8");
          int ch;
          while ((ch = inStreamReader.read()) != -1) {
            response += (char) ch;
          }
          try {
            JSONObject result = new JSONObject(response);
            return result;
          } catch (JSONException ex) {
            ex.printStackTrace();
          }
        } finally {
          inStream.close();
        }
      } else {
        throw new IOException("HTTP response code: " + rc);
      }
      return null;
    } finally {
      if (connection != null) {
        connection.close();
      }
    }
  }