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
christopherbecker
Posts: 28
Registered: ‎11-13-2012
My Device: none
My Carrier: 27768965251

Basic HTTP Get or POST data

Hi guys,

 

I'm new to the whole blackberry app development and, so far I'm enjoying it, BUT, I'm getting gray hair from retrieving data from my localhost php file.

 

Can someone give me a straight forward quick tutorial on how to do this? I've been trying to follow online tutorials, but none of them EVER work!

 

So far, I've got everything up and running.

 

my php file echo's "hello", just for now....

How do I access that php file and display the echo?

 

This is what I'm trying at this moment.

 

HttpConnection http = null;

StreamConnection s = (StreamConnection)Connector.open(url);
HttpConnection httpConn = (HttpConnection)s;
int status = httpConn.getResponseCode();

 

It says Connector.open "Unhandled exception type IOException";

I would GREATLY appreciate some help.

 

Thanks.

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

Re: Basic HTTP Get or POST data

start the MDS simulator with your simulator

use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/io/transport/ConnectionFactory...
----------------------------------------------------------
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.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Basic HTTP Get or POST data

You could probably start by using the HttpDemo sample.

 

However the trick here is probably that you do not know how to specify the connection method the device/simulator will use to connect, and you are probably being timed out.  Printout the message associated with the IOException you are handling, to see more detail of the actual Io error it is complaining about. 

 

To get default processing working on the Simulator, you need to start the MDS Simulator, or append ";deviceside=true" to your URL.

 

To appreciate the various options review this video:

http://supportforums.blackberry.com/t5/Java-Development/Networking-Transports-II/ta-p/446742

 

To understand how to set the connection method manually, see this:

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

 

However I recommend you look at using ConnectionFactory, as Simon pointed out in response to your first post here:

http://supportforums.blackberry.com/t5/Java-Development/http-get/m-p/1986983#M211526

 

Let us know if the above does not get you going. 

 

Finally - welcome to BlackBerry. Hope you enjoy it!

Please use plain text.
Contributor
christopherbecker
Posts: 28
Registered: ‎11-13-2012
My Device: none
My Carrier: 27768965251

Re: Basic HTTP Get or POST data

The thing is, everything is so confusing.....I try to look at the coding samples, but It just doesn't make sense.

 

Does anyone know of a tutorial that will tell me, we do this because of this, and this because of that, nothing fancy, I just want to retrieve some text, that's all.

 

I followed this, but even that doesn't work, it's too messy and complicated for the little basic thing I want to achive.

 

Thanks for the response.

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

Re: Basic HTTP Get or POST data

run the httpdemo sample, does it work?

I usually take a sample that does something similar and try my way from there.
----------------------------------------------------------
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
christopherbecker
Posts: 28
Registered: ‎11-13-2012
My Device: none
My Carrier: 27768965251

Re: Basic HTTP Get or POST data

Hmm, when I run the DEMO, it says "retrieving data" and does nothing else.

Please use plain text.
Contributor
christopherbecker
Posts: 28
Registered: ‎11-13-2012
My Device: none
My Carrier: 27768965251

Re: Basic HTTP Get or POST data

okay i got it working making a change.

 

c = Connector.open("http://localhost:8080/home.php;deviceside=true");

 

I changed the deviceside to true, but then it reads everything as text and ignores anything like html tags etc..

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

Re: Basic HTTP Get or POST data

localhost won't work, use the ip address instead.

and of course it reads anything as text, you just retrieve the file, you did not create a browser.
----------------------------------------------------------
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
christopherbecker
Posts: 28
Registered: ‎11-13-2012
My Device: none
My Carrier: 27768965251

Re: Basic HTTP Get or POST data

what is the difference between the false and the true?

 

It just keeps saying "retreiving data", even for the blackberry site.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Basic HTTP Get or POST data

I think this is a case where a little knowledge will help you understand the framework you are building upon. 

 

As an example, you don't just turn the key in your car and think that is what makes it go forward do you?  You understand that it only turns the starter motor, which turns the motor ....  A little knowledge about how the car works means you use it better. 

 

I recommend that you review the links I pointed you at.  They explain the connection methods and the meaning of the connection suffixes. 

 

OK?

Please use plain text.