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

Posts: 144
Registered: ‎12-20-2008
My Device: Not Specified

HTTP Get Stream connection

I want to retrieve the content of a php page thet returns a string it keeps failing wht is wrong here is the code



                    System.err.println("Abrir conexion");
                    s = (StreamConnection)Connector.open(_theUrl, Connector.READ, true);
                    HttpConnection httpConn = (HttpConnection)s;


enters up to here then fails i need to put the correct property

                   // httpConn.setRequestProperty("User-Agent", "BlackBerry/0.1");
                      int status = httpConn.getResponseCode();
                    if (status == HttpConnection.HTTP_OK)
                        java.io.InputStream input = s.openInputStream();
                        byte[] data = new byte[256];
                        int len = 0;
                        int size = 0;
                        StringBuffer raw = new StringBuffer();
                        while ( -1 != (len = input.read(data)) )
                            raw.append(new String(data, 0, len));
                            size += len;
                        java.util.Vector messages = parseMessage(raw.toString());
                catch (java.io.IOException e)

BlackBerry Development Advisor
Posts: 15,784
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: HTTP Get Stream connection

Please refer to the httpdemo included with the BlackBerry JDE for an example of making an HTTP connection.


What happens when the connection fails?  Is an exception thrown?  If so, what is it?  What BlackBerry model and handheld software version are you testing with?  You can find this under Options, About on the BlackBerry handheld.  What route is your connecting being made over?


What Is - Different ways to make an HTTP or socket connection
Article Number: DB-00396


Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker