Search code examples
httpblackberryjava-mecellular-network

HTTP Connection Parameters


I am using the HTTP Connection in the following way:

         HttpConnection _httpConnection = null;

         try {
             _httpConnection = (HttpConnection)Connector.open(_url);
         } catch(Exception e) { }

        byte [] postDataBytes = _postData.getBytes();
        _httpConnection.setRequestMethod(HttpConnection.POST);
        _httpConnection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
        _httpConnection.setRequestProperty("Content-Language", "en-US");
        _httpConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
        _httpConnection.setRequestProperty("Connection", "close");
        _httpConnection.setRequestProperty("Content-Length", Integer.toString(_postData.getBytes().length));

        os = _httpConnection.openOutputStream();
        os.write(postDataBytes);
        os.flush();

This HTTP Connection requires parameters to successfully open. For example on a WIFI network, it requires the ";deviceside=true;interface=wifi" to be added to the URL.

The problem is for the EDGE connection. Each country requires different parameters to be added. For example in lebanon it requires ";deviceside=false" but in KSA if i add this parameter the connection will not open. In USA it needs different types of parametes. The question is how to establish an HTTP connection for all the countries with the same parameters. So that the application will successfully have an internet connection no matter where it is downloaded.


Solution

  • Welcome to the confusing world of network transports on BlackBerry! You will want to start with the article Connecting your BlackBerry - http and socket connections to the world.

    Here is a simple example for "just give me a connection" (note, you will need to add appropriate error handling; also, myURL in the code below should have no connection descriptor info appended to it):

    ConnectionFactory factory = new ConnectionFactory();
    ConnectionDescriptor descriptor = factory.getConnection(myURL);
    if (descriptor != null) {
        _httpConnection = (HttpConnection) descriptor.getConnection();
        ...
    }