Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 39
Registered: ‎04-20-2010
My Device: 9550,8190
My Carrier: Developer
Accepted Solution

httpconnect not work on real device

Hello everyone read from this link

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

 

but still not work :smileysad:, it works fine on emulator

 

here is my code

 

HttpConnection httpConn =

(HttpConnection) Connector.open(http://192.168.172.17:2000/login;deviceside=true, Connector.READ_WRITE);
            httpConn.setRequestMethod(HttpConnection.POST);
            httpConn.setRequestProperty("User-Agent",
                    "Profile/MIDP-2.0 Configuration/CLDC-1.0");
            httpConn.setRequestProperty("Accept_Language", "en-US");

 

String oPostData = "username=" +username + "&" + "password="+password;
                    
            os =httpConn.openOutputStream();
            os.write(oPostData.getBytes());
            os.flush();

 

 

thanks in advance

Developer
Posts: 19,618
Registered: ‎07-14-2008
My Device: Not Specified

Re: httpconnect not work on real device

Can you describe exactly what you see.  "Does not work" is not helpful.  Does it time out?  Do you get an exception?

 

Since you have reviewed that KB article, you will see that to use ";deviceside=true", you need to specify APN information.  Have you done so?

 

Have you tried the WAP 2 option using the code from that article?  Is there is Wap Browser on your device?

 

Do you have WiFi on the device?  Have you tried that?

Developer
Posts: 272
Registered: ‎05-24-2010
My Device: DEV Alpha C & BB 9720
My Carrier: Idea and Airtel

Re: httpconnect not work on real device

check what type connection you have....

based on that give the connection parameters...

 

 

use the below function..and append the return string to your connecting url...

 

 

public static String getConnectionPerameter() {
        String connectionParameters = "";
        if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
            // Connected to a WiFi access point
            connectionParameters = ";interface=wifi";
        } else {
            int coverageStatus = CoverageInfo.getCoverageStatus();
            ServiceRecord record = getWAP2ServiceRecord();
            if (record != null
                    && (coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
                // Have network coverage and a WAP 2.0 service book record
                connectionParameters = ";deviceside=true;ConnectionUID="
                        + record.getUid();
            } else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
                // Have an MDS service book and network coverage
                connectionParameters = ";deviceside=false";
            } else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
                // Have network coverage but no WAP 2.0 service book record
                connectionParameters = ";deviceside=true";
            }
        }
        return connectionParameters;
    }

Contributor
Posts: 39
Registered: ‎04-20-2010
My Device: 9550,8190
My Carrier: Developer

Re: httpconnect not work on real device

thank you for you replay i try with your code i got the string return is ";interface=wife", i put it on url, but still not work it get an exception, i display exception by getMessage() but it return null.

Developer
Posts: 19,618
Registered: ‎07-14-2008
My Device: Not Specified

Re: httpconnect not work on real device

For exceptions, I generally use toString to get the text.

 

Please think carefully before using the code given.  I personally do not think it is correct, especially as I think it should have BES as the preferred connection method if that is available. 

 

And be aware that this code is actually from Beginning BlackBerry Development, by Anthony Rizk.  Here is the missing bit of code too:

 

    private ServiceRecord getWAP2ServiceRecord() {
        ServiceBook sb = ServiceBook.getSB();
        ServiceRecord[] records = sb.getRecords();

        for (int i = 0; i < records.length; i++) {
            String cid = records[i].getCid().toLowerCase();
            String uid = records[i].getUid().toLowerCase();
            if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") == -1
                    && uid.indexOf("mms") == -1) {
                return records[i];
            }
        }

        return null;
    }

Developer
Posts: 272
Registered: ‎05-24-2010
My Device: DEV Alpha C & BB 9720
My Carrier: Idea and Airtel

Re: httpconnect not work on real device

am sorry for missing that code...

 

thanks regards yakub pasha...

Developer
Posts: 1,178
Registered: ‎02-19-2009
My Device: Not Specified

Re: httpconnect not work on real device

Developer
Posts: 19,618
Registered: ‎07-14-2008
My Device: Not Specified

Re: httpconnect not work on real device

sblantipodi - does your response help the poster?

Developer
Posts: 1,178
Registered: ‎02-19-2009
My Device: Not Specified

Re: httpconnect not work on real device

[ Edited ]

sure, it helps him not loosing time on a failed cause if he hasn't the access to BISB.

Contributor
Posts: 39
Registered: ‎04-20-2010
My Device: 9550,8190
My Carrier: Developer

Re: httpconnect not work on real device

thanks you all, it doesnt work, it get an exception at this line httpConn.getResponseCode() if i try with real device