BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-11-2007, 02:03 AM   #1 (permalink)
New Member
 
Join Date: Apr 2007
Model: 7100T
Carrier: airtel
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How to establish Http Connection

Please Login to Remove!

I'm beginner in blackberry coding.Can anyone help me out in creating a Http connection to the blackberry device to the webpage which is linked to the database.
Please try to help me out in prividing a sample code application wherein the application when it is launched in the BlackBerry device establishes the connection the the localhost server and gets the details from the databse and displays it to the blackberry device
I hope i ll get some solution her since i;m a beginner.please help me out
Offline  
Old 04-11-2007, 01:44 PM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
 StreamConnection s = null;
                HttpsConnection connection = null;
                OutputStream outputStream = null;
                String result = new String();
                String httpConnString = new String();
                try {

                 
                     
                        httpConnString = "your url Here";
                        connection = (HttpsConnection) Connector.open(httpConnString);

                        connection.setRequestMethod(HttpsConnection.POST);

                        outputStream = connection.openOutputStream();

                        outputStream.write(connString.getBytes());


                        InputStream inputStream = connection.openInputStream();
                        byte[] responseData = new byte[10000];
                        int length = 0;
                        StringBuffer rawResponse = new StringBuffer();
                        while (-1 != (length = inputStream.read(responseData))) {
                                rawResponse.append(new String(responseData, 0, length));
                        }

                     

                   
                        int responseCode = connection.getResponseCode();
                        if (responseCode != HttpConnection.HTTP_OK) {
                                throw new IOException("HTTP response code: " + responseCode);
                        }

                        
                         result = rawResponse.toString();

                } catch (Exception e) { your exception logging goes here }
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

(1PCS) BR25H080FVT-WCE2 IC EEPROM 8KBIT 5MHZ 8TSSOP 25H080 BR25H080
$2.65
(1PCS) BR25H080FVT-WCE2 IC EEPROM 8KBIT 5MHZ 8TSSOP 25H080 BR25H080 picture(5PCS) BR24G512FJ-3AGTE2 IC EEPROM 32KBIT 1MHZ 8SOP 24G512 BR24G512
$8.62
(5PCS) BR24G512FJ-3AGTE2 IC EEPROM 32KBIT 1MHZ 8SOP 24G512 BR24G512 picture(5PCS) BR9040F-WE2 IC EEPROM 4KBIT 1MHZ 8SOP 9040 BR9040
$6.47
(5PCS) BR9040F-WE2 IC EEPROM 4KBIT 1MHZ 8SOP 9040 BR9040 picture(5PCS) BR93LC46F-WE2 IC EEPROM 1KBIT 1MHZ 8SOP 93LC46 BR93LC46
$6.27
(5PCS) BR93LC46F-WE2 IC EEPROM 1KBIT 1MHZ 8SOP 93LC46 BR93LC46 picture(5PCS) BR9020RFV-WE2 IC EEPROM 2KBIT 1MHZ 8SSOP 9020 BR9020
$5.88
(5PCS) BR9020RFV-WE2 IC EEPROM 2KBIT 1MHZ 8SSOP 9020 BR9020 picture






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