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
aktaion
Posts: 11
Registered: ‎04-09-2010
My Device: Curve-9000
My Carrier: AT&T
Accepted Solution

unable to get data from Httpconnection and parse that data on actual device

Hi ,

 

I am using Blackberry Bold 9000 device. I am fetching xml using Http connection. On my simulator it is working fine.(Please note that i will have to keep MDS-CS running while HTTP request.)

 

but when i install application on device it only shows UI elements. No data is downloaded from HTTP connection.

 

Do i have to apply any settings on device? please suggest.

 

 

Thanks,

Aktaion.

Please use plain text.
Developer
ibarrera
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

Re: unable to get data from Httpconnection and parse that data on actual device

Can you post some code to see how you are doing the connection  so we can help you?

Please use plain text.
New Contributor
zexu-xu
Posts: 7
Registered: ‎04-07-2010
My Device: Blackberry 9000
My Carrier: China Mobile

Re: unable to get data from Httpconnection and parse that data on actual device

Make sure you set the connection string correctly.

 

There is a very good guide here: http://www.localytics.com/blog/post/how-to-reliably-establish-a-network-connection-on-any-blackberry...

Please use plain text.
Developer
simon_hain
Posts: 15,876
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: unable to get data from Httpconnection and parse that data on actual device

and don't forget that networking should be done in a thread
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
aktaion
Posts: 11
Registered: ‎04-09-2010
My Device: Curve-9000
My Carrier: AT&T

Re: unable to get data from Httpconnection and parse that data on actual device

[ Edited ]

Hi,

 

Here is my code that i used to get response from remote server using Httpconnection:

 

HttpConnection httpConn = null;
StreamConnection s = null;

StringBuffer rawResponse;
         
s = (StreamConnection)Connector.open("http://www.samplewebsite.com/response.xml");
httpConn = (HttpConnection)s;
len = (int)httpConn.getLength();
rawResponse=new StringBuffer();
                               
if (len >= 0)
{
             InputStream inputStream = httpConn.openInputStream();
             byte[] responseData = new byte[10000];
             int length = 0;
                                
             while (-1 != (length = inputStream.read(responseData)))
             {
                     rawResponse.append(new String(responseData, 0, length));
             }
}
System.out.println("WOW---Search Result ---->"+rawResponse.toString());
}

 

Please suggest if i need to modify in this code.

 

A.

Please use plain text.
Developer
simon_hain
Posts: 15,876
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: unable to get data from Httpconnection and parse that data on actual device

you can make it a lot simpler, like this: bytes[] data = IOUtilities.streamToBytes(httpConn.openInputStream)); you can also check the responseCode of the connection before you try to download anything. check some samples about using suffixes to make your connection more reliable.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
aktaion
Posts: 11
Registered: ‎04-09-2010
My Device: Curve-9000
My Carrier: AT&T

Re: unable to get data from Httpconnection and parse that data on actual device

[ Edited ]

Hi Zexu-xu,

 

The link you provide gave me details where i was missing the things. Actually for wifi use i forget to add "interface=wifi" flag while opening the connection.

 

Thanks,

Aktaion.

Please use plain text.