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
Developer
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

 

 

try
                {
                    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());
                        processMessages(messages);
                        input.close();
                    }
                    s.close();               
                }
                catch (java.io.IOException e)
                {
                    System.err.println(e.toString());
                }

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,663
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

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

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

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
Please use plain text.