BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 08-25-2008, 06:07 AM   #1 (permalink)
New Member
Join Date: Aug 2008
Model: 8110
Carrier: Airtel
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default What is the best way to programmatically get APN/Gateway IP and make a HTTP Connectio

Please Login to Remove!

Hi All,

I have written a small BB application to access a HTTP URL. I am using the regular HTTPConnection class for this (Code Attached). This is the behavior observed.

1. My application works fine with a simulator using MDS.

2. My Provider does not provide access to a BES server. However, my phone had a valid APN and Gateway IP in the WAPTransport[WAP]. Hence I modified my application to pick up this information and establish a connection over GPRS. In this case the connection establishment did work.

My question is as follows:

I also tried to run my application on a BB in another network. On this phone there is no entry with the name WAPTransport[WAP] in the Service Book. In this case my application fails (gives an exception on the line marked with RED). But other applications such as the browser continue to work. Where do these applications get the APN/Gateway IP from?

Appreciate any help in this regard,

Thanks in Advance,

public class ReadHttpFile extends Thread {
         HttpConnection httpConnection = null;
         InputStream inputStream = null;
         int responseCode;
         public boolean isInvalidFile=false;
         String url;
         StringBuffer URLString;

        ReadHttpFile(String URL){
            url = URL;
            URLString = new StringBuffer();

                ServiceBook serviceBook = ServiceBook.getSB();
                ServiceRecord[] records =
                for(int i = 0; i < records.length; i++){
                        String networkAddress =
                        url = URLString.toString();

            }catch(Exception e){
                System.out.println("Exception : "+e.toString());


        public void run() {
            }catch(IOException ie){
                System.out.println("IOException : "+ie);
            }catch(Exception e){
                System.out.println("Exception : "+e);


            public void ReadData(String url) throws IOException{
                try {

                        httpConnection =

                        if(httpConnection != null){
age", "en-US");
, "text/xml; charset=utf-8");
                            responseCode = httpConnection.getResponseCode();
                            if (responseCode != HttpConnection.HTTP_OK) {
                                System.out.println("Http connection :
                                System.out.println ("Http connection : OK
                                inputStream =
                                StringBuffer sb = new StringBuffer();
                                int ch;
                                while ((ch = != -1) {
                                    sb.append((char) ch);
                                System.out.println("XML "+ sb .toString());
                            System.out.println("Connection object : Null ");

                    }catch(IOException ioe){
                        System.out.println("Exception : "+ ioe.toString());
                    }catch(Exception e){
                        System.out.println("Exception : "+ e.toString());
                    } finally {
                        if (inputStream != null)
                        if (httpConnection != null)


Old 08-25-2008, 09:21 AM   #2 (permalink)
Thumbs Must Hurt
Join Date: Apr 2006
Location: Boston
Model: 8900
Carrier: AT&T
Posts: 98
Post Thanks: 0
Thanked 0 Times in 0 Posts


You can find a listing of APNs and appropriate carrier-specific information at a number of places on the Internet. Use Google, and do a search on BlackBerry APN settings. Pinstack and BlackBerryFAQ have good lists.

As for how the browsers know what to use without having it specified in the TCP settings, my guess is as follows: the carrier-specific browser (e.g., Media.Net for AT&T/Cingular) already knows what the proper APN settings must be (doh!). So I'd guess that they just hard-code it.

The BlackBerry browser is a different story. It could know the carrier-specific APN settings (you can find out who the carrier is via the Vendor API) for each carrier - there aren't that many of them, and RIM would know what their settings are. Another possibility is that the BlackBerry browser avoids them altogether and uses its own hard-coded APN information, through a server that they maintain.


Karl G. Kowalski
Owns a RAZR
Develops for BlackBerry
So next phone will iPhone 3G!
Old 08-25-2008, 02:23 PM   #3 (permalink)
Thumbs Must Hurt
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts

It's good to know about the various connection modes available to you before you whip up connection code.

They are:
WIFI - You can make a wifi connection using the service book record (there are other ways but you have to be an alliance member to have access to that information)
BES - deviceside=false
BIS - You need to have your application approved by RIM alliance to use this or they will block your traffic to and from whatever server you're running.
WAP - You can make a wap connection from the associated service book record (you can use the connectionUID=<wap record uid> parameter. RIM made this information public in a tutorial video so it is no longer covered by their NDA)
Direct TCP - You need the apn information. The string is deviceside=true;apn=<apn>

Also some more detail about browsers:

There are 3 (main) types of browsers: BES browser, BIS browser and WAP browser. Generally speaking, most corporate users will be using their BES browser, which tunnels all traffic through a BES. Consumer users will likely be using a BIS browser, and that goes through the carrier's BIS, which RIM moderates. WAP browsers use the wap service record stored on the phone to make the connection. These service records contain references to native routines and the OS code knows how to connect to the various wap gateways. You can also manually specify wap gateway ip's and ports yourself.

You can manually load the browser with a service record and have it use the associated connection type.

Last edited by CELITE : 08-25-2008 at 02:25 PM.

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.