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: 153
Registered: ‎09-03-2009
My Device: Not Specified
Accepted Solution

Problem about httpconnection

I need get the xml file from server and i use httpconnection.  Even i use the simple code . It also can not work. what's the problem

The code show below: 

 public class XMLTestScreen extends MainScreen {

public XMLTestScreen() {

setTitle("HttpConnection Demo");

try {

HttpConnection coon = (HttpConnection) Connector

.open("http://www.google.com.sg");

int status = coon.getResponseCode();

if (status == HttpConnection.HTTP_OK) {

Dialog.alert("GET");

add(new LabelField("get"));

} else {

Dialog.alert("Nothing");

add(new LabelField("Nothing"));

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

Developer
Posts: 153
Registered: ‎09-03-2009
My Device: Not Specified

Re: Problem about httpconnection

I also use httpconnection to load image from website,The code from http://www.coderholic.com/blackberry-webbitmapfield/

But it also can not work. I mean in my code , any app can not work if the code has httpconnection code. Do i need set the simulator? 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Problem about httpconnection

"doesn't work" is a little too non-specific to respond to.

 

There are a several issues with your code, starting with "you cannot make a HTTP connection in the event thread".

 

You are also not requesting any specific connection type (URL suffix), so you are going to get a BES connection. On the simulator, this requries that you start the MDS-CS program along with the sim.

 

I suggest that you start out by reviewing the HTTPDemo code that ships with the JDE, and by looking at the Peter Strange HTTP sticky thread on this forum, and doing some research on the forum.

 

 

 

 

Developer
Posts: 153
Registered: ‎09-03-2009
My Device: Not Specified

Re: Problem about httpconnection

Thanks . you mean that i need to get BES connection first? Ok, may be i need to study the Http Demo first
Developer
Posts: 153
Registered: ‎09-03-2009
My Device: Not Specified

Re: Problem about httpconnection

But i don't need use BES, I build the server by meself. It juse like a url.
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Problem about httpconnection

You need to look at this:

 

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

 

If you do not specify a URL connection parameter, then your HTTP (with very few exceptions) will work only on a unit with BES.

 

If you are trying to run this code on the simulator, then you need to start MDS-CS along with the simulator. MDS-CS provides the BES-like connectivity to the web.

 

If you are running on a device, then this will only work on a device with BES (with few exceptions). Read the above article, and read the Peter Strange sticky thread on this forum.

 

Developer
Posts: 153
Registered: ‎09-03-2009
My Device: Not Specified

Re: Problem about httpconnection

Thanks very much. The url like : http://www.myurl/..xml

I just need get the xml data.

Thank you  

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

Re: Problem about httpconnection

Unfortunately to understand any code that is supplied to you, you are gong to have to do some learning.  RexDoug has suggested a number of places, let me suggest a few more.

 

The Developer Guide is a very good read, you can pick it up for 4.6 here.

http://docs.blackberry.com/en/developers/deliverables/3802/development.pdf 

This has a Chapter called "Creating Connections" inside which is a promisingly titled section called "Fetching Data..." sounds just like what you want.

 

To save you looking, the sticky Thread that RexDoug suggested is here:

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=29103

 

You will also find some free sample code around that does something like what you want, including this one:

http://developerlife.com/tutorials/?p=884

Developer
Posts: 153
Registered: ‎09-03-2009
My Device: Not Specified

Re: Problem about httpconnection

Thanks very much. I learnt the document from

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

 

So the question is : If i wan to use httpconnection code , i shoud have BES or BIS?


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

Re: Problem about httpconnection

You need to carefully review the sticky Thread and the network video.  That should explain the differences between BIS and BES.  It should also explain the different connection methods. 

 

 

Also I don;t think you are clear on the terminology.  Hopefully this will help:

 

BES - Blackberry Enterprise Server, a BES device is a corporate device connected to a BES

 

BIS - BlackBerry Internet Service - this is the service that supports a personal (non corporate) user

 

BES/MDS - the usual communication method used by BES devices

 

BIS-B - a general communication method available to almost all devices, but requiring Alliance Partner status and approval to activate. 

 

So when you ask questions about BES and BIS, please state clearly what you are talking about because the terms can mean a number of things.