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
djpinto
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

According to what I've been seeing already ha way to detect what is connected. But HTTPDemo should not give in mobile phone?

I just tried to run the application on the mobile phone with wifi option and set the "deviceside = false" and yet the message that appears is "java.io.IOException" I do not understand why it does not work! : S

Please use plain text.
Contributor
djpinto
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

The modify code is:

 

HttpConnection httpConn = (HttpConnection)Connector.open(getUrl()+";interface=wifi");

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

Re: Get string from url

You might remember this KB article that I referenced previously.

 

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

 

Have another look through this and see what each of the connection strings actually means.

 

For WiFi you need

";interface=wifi"

 

Note that these must be typed exactly as you see them.  So "deviceside = false" won't work because it does not have a ";" to start and there are spaces in it.  You should use

";deviceside=false"

This is for BES/MDS connections, I doubt your phone is a BES phone. 

 

But I really recommend that you do not try this way.  Use ConnectionFactory. 

Please use plain text.
Contributor
djpinto
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

I've been researching the FactoryConnection and tried to implement but not how to get the text of this connection!

 

My code is:

 

//preferred transport types
int[] preferredTransportTypes = {TransportInfo.TRANSPORT_TCP_WIFI, TransportInfo.TRANSPORT_MDS,
TransportInfo.TRANSPORT_WAP2, TransportInfo.TRANSPORT_BIS_B, TransportInfo.TRANSPORT_TCP_CELLULAR,
TransportInfo.TRANSPORT_WAP};

//set preference in connection factory
ConnectionFactory factory = new ConnectionFactory();
factory.setPreferredTransportTypes(preferredTransportTypes);
factory.setAttemptsLimit(3);


//create connection using connectionDescriptor
ConnectionDescriptor conDescriptor = factory.getConnection(url);
HttpConnection httpConnection=null;

if(conDescriptor !=null){
httpConnection = (HttpConnection) conDescriptor.getConnection();
transportType = conDescriptor.getTransportDescriptor().getTransportType();
}

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

Re: Get string from url

If you have looked at HttpDemo (sorry I think I called it htmlDemo), you will see these lines:

 

                    StreamConnection s = null;

                    s = (StreamConnection)Connector.open(getUrl());

                    HttpConnection httpConn = (HttpConnection)s;

 

Basically after this line in your code:

 

httpConnection = (HttpConnection) conDescriptor.getConnection();

 

you have an HTTP connection.  And so the processing continues like HttpDemo, i.e. get response code and then read the input stream.

 

BTW, I recommend IOUtilities.streamToBytes as a quick way to read the entire Stream in.

 

Hope this helps.   

 

 

Please use plain text.
Contributor
djpinto
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

Have a working code that I can show to see if I can understand putting it to work right?

 

Have tou is all confused and I really need to put this to work ASAP!

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

Re: Get string from url

Please use plain text.
Contributor
djpinto
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

I had already found this example and what brings me back is the number 302, which does not know what it means!

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

Re: Get string from url

Is this the response code you are getting? 

 

If so, use the search facility here or use your favorite Internet search engine and look for Http code 302.  Hopefully that will explain it.

 

With redirects you need to chase down the actual address yourself - Browsers do this for you but when getting the data yourself you need to do it. 

 

 

Please use plain text.
Contributor
djpinto
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

But with this code should not show the text received?

Please use plain text.