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: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Sample HTTP Connection code and BIS-B Access

Good news: I just got approved for push service evaluation. I'll have to carve some time out to try it and will report back.

 

 

Developer
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Sample HTTP Connection code and BIS-B Access

Well, it looks like these guys have found a solution to this issue, and it seems to be field-tested.

 

http://www.localytics.com/blog/2009/how-to-reliably-establish-a-network-connection-on-any-blackberry...

 

I'll be implementing their method and testing moving forward.

Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: Sample HTTP Connection code and BIS-B Access

Yes peter i have , but i need to know how to use your api , if i am making a bis connection to my webserver , do i what are the things do i need to do to easily to do that . I read when u talked about passing my http url to the URlFactory class but do i need to register my push registeration details to my app during app loading or do i need to d the push registeration anytime i make a htp request , i am so confused your insight will do a lot of help.

New Contributor
Posts: 4
Registered: ‎04-11-2012
My Device: 8900
My Carrier: Xl

Re: Sample HTTP Connection code and BIS-B Access

Hi...I'm a starter in Blackberry development.
The code run perfectly. And I want to get only the data so I can parse with JSON parsing, instead of the complete log.

 

how to get the string content only?

 

thx 

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

Re: Sample HTTP Connection code and BIS-B Access

The TestScreen sample has code that gets the bytes:

 

        HTTPRequestRunnable getData = new HTTPRequestRunnable(_urlToTry.getText(), postData, connectionType, true);
        if ( HttpLibrary.getResponse(getData, "Testing") < 0 ) {
            // has been cancelled by user
            Status.show("Request cancelled");
        } else {
            String errorMessage = getData.getErrorMessage();
            if ( errorMessage == null ) {
                if ( getData.gotResponse() ) {
                    byte [] response = getData.getResponse();

 

Remember that communication is always done in bytes, so if you need to convert this to a String for your processing, then you can use this:

 

String dataString = new String(response, "UTF-8")

New Contributor
Posts: 4
Registered: ‎04-11-2012
My Device: 8900
My Carrier: Xl

Re: Sample HTTP Connection code and BIS-B Access

[ Edited ]

So if I have a package of JSON string from my webservice, it will be saved to dataString variable?

 

 

btw Where should I put the      String dataString = new String(response, "UTF-8");    code?

 

I got an error "add throw exception"

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

Re: Sample HTTP Connection code and BIS-B Access

1) So if I have a package of JSON string from my webservice, it will be saved to dataString variable?

That is the idea....

 

2) So if I have a package of JSON string from my webservice, it will be saved to dataString variable?

I have no idea in your application.  In the code above you will add it after this...

byte [] response = getData.getResponse();

 

2) I got an error "add throw exception"

I presume that was when you added this line:

String dataString = new String(response, "UTF-8");

This line can possibly throw an exception, so you need to include the code in a try/catch.Something like this:

String dataString;

try {

dataString = new String(response, "UTF-8");

} catch (Exception e) {

// UTF-8 us supported so this Exception will never be thrown....

}

 

New Contributor
Posts: 4
Registered: ‎04-11-2012
My Device: 8900
My Carrier: Xl

Re: Sample HTTP Connection code and BIS-B Access

Nicely done :thumbs: big thanks peter Smiley Very Happy
Developer
Posts: 100
Registered: ‎01-13-2011
My Device: Not Specified

Re: Sample HTTP Connection code and BIS-B Access

Hello,
Developer
Posts: 100
Registered: ‎01-13-2011
My Device: Not Specified

Re: Sample HTTP Connection code and BIS-B Access

Hello,

 

 I am using some code of httpLibrary to handle http 302, what I want is to retry connection with url gotted from response header, I see in HttpRequestRunnable its says to try again but only do a Thread.yield not rerun the runnable, how could I reach my goal?