Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Regular Contributor
Cali03
Posts: 52
Registered: 07-01-2010
My Carrier: Vodafone

HttpConnection on 9800 don't work?

Hi,

 

My midlet work fine in 9700, 9300, 8320 but today we tryed the 9800 torch and we got an error trying to connect to internet with HttpConnection.

 

We tryed to configure manually the apn but don't work.

 

Something change on this model? Need to change the code for etablish connection?

 

Here is the code :

 

[CODE]

 

http = (HttpConnection) Connector.open(url);
 http.setRequestMethod(HttpConnection.POST); 
 http.setRequestProperty("CONTENT-TYPE", "application/x-www-form-urlencoded");
 http.setRequestProperty("Content-Language","es");                    
 http.setRequestProperty("Content-Length", Integer.toString(rawData.length()));
 outStrm = http.openOutputStream();

 

[/CODE]

 

But this code create an exception ...

 

Thanks

BlackBerry 8900 and 9700
Please use plain text.
Developer
simon_hain
Posts: 10,780
Registered: 07-29-2008
My Carrier: O2 Germany

Re: HttpConnection on 9800 don't work?

and the exception would be? crystall ball all cloudy :smileyhappy:

 

depending on the connection type of the device you may have to use a connection suffix to connect. check the sticky thread about it or use peters sample code.

----------------------------------------------------------
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.

peter_strange wrote:
"This process should happen traumatically for you in both JDE and Eclipse."
Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: HttpConnection on 9800 don't work?

[ Edited ]

I think there is a potential bug in your code too:

 

You say the data is URL encoded with this:

http.setRequestProperty("CONTENT-TYPE", "application/x-www-form-urlencoded");

 

But you set the length to this:

 http.setRequestProperty("Content-Length", Integer.toString(rawData.length()));
I'm guessing rawData is a String, in which case, you will need to URL Encode it.  When you do that, the encoding will change things like "." to %2F - in other words you will get more bytes than the number of characters in the String.  If you do not URL encode it, then you run the risk of your data not being recognized.
So always get your data in byte form before you determine its length. 
Please use plain text.
Regular Contributor
Cali03
Posts: 52
Registered: 07-01-2010
My Carrier: Vodafone

Re: HttpConnection on 9800 don't work?

Hi,

 

Thanks for the advice peter.

I fixed it i think now i do :

 

 

http.setRequestProperty("Content-Length", Integer.toString(rawData.getBytes().length));

But the problem with the 9800 still.

I try to read your post but my english it's too bad for unterstand all.

Maybe i need to play with the deviceside and add this code no?

 

;deviceside=true

 

Thanks

BlackBerry 8900 and 9700
Please use plain text.
Developer
simon_hain
Posts: 10,780
Registered: 07-29-2008
My Carrier: O2 Germany

Re: HttpConnection on 9800 don't work?

re-read peters post, you did not change your code correctly.

----------------------------------------------------------
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.

peter_strange wrote:
"This process should happen traumatically for you in both JDE and Eclipse."
Please use plain text.
Regular Contributor
Cali03
Posts: 52
Registered: 07-01-2010
My Carrier: Vodafone

Re: HttpConnection on 9800 don't work?

Hi simon_hain

 

Peter says : 

 

So always get your data in byte form before you determine its length. 

 

So i changed the line :

 

http.setRequestProperty("Content-Length", Integer.toString(rawData.length()));

 

for : 

 

http.setRequestProperty("Content-Length", Integer.toString(rawData.getBytes().length));

 

I think that is good.

BlackBerry 8900 and 9700
Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: HttpConnection on 9800 don't work?

Let us just make certain we all know what is going on here.

 

As SImon says, your code change may not be accurate.  Here is the code from the sample connection I posted here:

http://supportforums.blackberry.com/t5/Java-Development/Sample-HTTP-Connection-code-and-BIS-B-Access...

I have removed redundant lines

 

 

byte [] postBytes = _postParameters.getBytes();
_httpConnection.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, Integer.toString(postBytes.length));
os = _httpConnection.openOutputStream();
os.write(postBytes);
os.flush();
os.close();
os = null;

 

So I get the bytes in byte [] form, ready to write, before I calculate the length. 

 

That said, I think when you say:

"I try to read your post but my english it's too bad for unterstand all."

 

You are either talking about the post mentioned above or this long one:

http://supportforums.blackberry.com/t5/Java-Development/Connecting-your-BlackBerry-http-and-socket-c...

 

I'm sorry that your English is not up to reading what I have written.  I sympathize.  My French/German/Spanish/<insert language of choice> is not good enough to even get as far as you have! 

 

However I do try to write as clearly as I can knowing non English speakers read this forum.  So I'm not sure that I can explain anything more clearly. 

 

I would recommend that you review the second Thread I mentioned above, especially the "Required Reading" which is mainly RIM stuff.  Hopefully it is clearer than what I wrote.

 

Finally we must get back to the point of this Thread.  You said:

"But this code create an exception ..."

Simon said:

"and the exception would be?"

 

Can we have the answer to Simon's question please.  It will help us understand the problem you are having.

 

I strongly suspect that you are managing to use default connection methods in the phones you have tested, and that the Torch does not have one.  So in fact, your connection on the other devices was more by accident than by design, and you need to confirm exactly what your connection method is to make sure that you know what you should be looking for.

 

To help with this, you could use the Network Diagnostics:

http://supportforums.blackberry.com/t5/Java-Development/What-Is-Network-API-alternative-for-legacy-O...

 

or use the code that I supplied in the first post I mentioned.  I suggest my code because it logs everything that it does, so you can find out your problems quicker.  But the network diagnostics is a much more complete test. 

 

Anyway, lots for you to look at, sorry this is not easy, good luck and come back to us when you need more or you can tell us what the Exception was.

 

 

 

Please use plain text.
Regular Contributor
Cali03
Posts: 52
Registered: 07-01-2010
My Carrier: Vodafone

Re: HttpConnection on 9800 don't work?

Hi,

 

The exception message is : Tunel failed.

 

Best Regards

BlackBerry 8900 and 9700
Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: HttpConnection on 9800 don't work?

[ Edited ]

This suggests you have not coded the appropriate APN values (and user and password perhaps) in the Options.  This should be explained in a number of places, including this KB article:

 

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

 

 

Please use plain text.
Regular Contributor
Cali03
Posts: 52
Registered: 07-01-2010
My Carrier: Vodafone

Re: HttpConnection on 9800 don't work?

Hi peter,

 

The apn are configurated on the blackberry and i also try with :

 

http = (HttpConnection) Connector.open(url + "";deviceside=true;apn=movistar.es;tunnelauthusername=movistar;tunnelauthpassword=movistar");

 

and get tunel failed

 

and with 

 

http = (HttpConnection) Connector.open(url + "";deviceside=false");

 

Invalid url parameter.

 

Best regards

 

BlackBerry 8900 and 9700
Please use plain text.