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
javame_black
Posts: 115
Registered: ‎10-04-2008
My Device: Not Specified
Accepted Solution

Please Help! Problem in using http for calling url?

Hi,

 

I am developing application for Blackberry 8830 which is cdma device. I want to develop application which uses http for calling url and gets the response. For using http whatever I have read there are about 5-6 ways. But the only one that fits my requirements is Direct TCP. But my service provider in India i.e. Tata Indidcom says it does not have APN settings for CDMA phones. What shall I do now. I really dont know if this is the only problem.  I have this thread 

 

Different ways of connecting with Http.

 

There are six ways mentioned as below :-

 

1. Blackberry Enterprise Server using Blackberry MDS - I dont have Blackberry Enterprise server so this is not possible.

 

2. Blackberry Internet Service - This requires Alliance with RIM so still not thuought about it.

 

3. Direct TCP - Not getting APN settings

 

4. Wi-Fi Network - I am not in Wi-Fi network so this is also out of equation.

 

5. WAP Gateway - Not looked into that yet. 

 

The only possible way I thought was Direct TCP but it requires APN settings but the message I got from Tata people is that APN settings is supported for GSM based phones and not for CDMA phones. So is there any way out, if yes then please let me know, its urgent.

 

Below is the code I am using for connecting. 

 

 

HttpConnection httpConnection = null; DataInputStream dis = null; DataOutputStream dos = null; url = "http://mailonphone.com:8180/automaticlicensing/LicensingServlet?" + "UserName=ilesh&Password=ilesh123&SiteCode=012345678901234567890&" + "ScratchCard=05533978;deviceside=true"; System.out.println("URL=>" + url); try { httpConnection = (HttpConnection)Connector.open(url, Connector.READ_WRITE); httpConnection.setRequestMethod(HttpConnection.POST); InputStream istrm = httpConnection.openInputStream(); String resMsg = httpConnection.getResponseMessage(); System.out.println("REsponse Message=" + resMsg); int length = (int)httpConnection.getLength(); String str; if (length != -1) { byte servletData[] = new byte[length]; istrm.read(servletData); str = new String(servletData); } else // Length not available... { ByteArrayOutputStream bStrm = new ByteArrayOutputStream(); int ch; while ((ch = istrm.read()) != -1) bStrm.write(ch); str = new String(bStrm.toByteArray()); bStrm.close(); } System.out.println("Registeration Key=>"+str); int in=str.indexOf("<html>"); int en=str.indexOf("</html>"); key=str.substring(in+6,en); key=key.trim(); System.out.println("KEy="+key); } catch(Exception ex) { System.out.println("Error while calling url"); key = "In catch while calling url"; //sendMenuItem.setText("Message not send"); } }

If there is some problem in the code then let me know too. I was not able to test this even on the emulator since MDS is not working on simulator. Would look into that, but if its related to some other issue then please let me know.

 

Thanks & Regards

Sunil

 

 

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

Re: Please Help! Problem in using http for calling url?

Your code, as it stands (i.e. with ";deviceside=true") can be tested on the Simulator.  If you put ";deviceside=true" then the Simualtor will connect without MDS.

 

This link - supplied by simon_hain, is the best list of carriers and APN settings I have seen.  I can not find your carrier on it.

 

Since it would appear you really can't use direct TCP, then I would suggest that you try a WAP 2.0 gateway, using the code supplied in the KB article you have already linked to.

 

Please use plain text.
Developer
javame_black
Posts: 115
Registered: ‎10-04-2008
My Device: Not Specified

Re: Please Help! Problem in using http for calling url?

Even after writing deviceside=true its not connecting through simulator. It goes into catch. I would trying out WAP 2.0, just hoping that it works.

 

Thanks & Regards

Sunil

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

Re: Please Help! Problem in using http for calling url?

The exception that it is throwing into the catch, will give you a clue as to the problem.  I suspect there is something wrong with your data, for example, you have specified HttpConnection.POST, but you don't supply any post data, so I think you really meant HttpConnection.GET.

 

WAP 2.0 will not work on the simulator.

 

I recommend that you get your code working using the Simulator (i.e. ";deviceside=true") before you expose yourself to the problems of trying to connect on a real device.

Please use plain text.
Developer
javame_black
Posts: 115
Registered: ‎10-04-2008
My Device: Not Specified

Re: Please Help! Problem in using http for calling url?

Thanks again,

 

I have tried WAP 2.0 but it says gives error on device as "Error while starting application: Trying to use secure API". I think this comes since I am using ServiceBook which might be a secure API. Or is it something different. I am testing the application on Blackberry 8830 which is CDMA device with version 4.2.2 and I am using JDE 4.6.0 Is it causing the problem.

 

Would try to use Get method instead of Post in hope that it works. I never knew programming in Blackberry would be... It was fairly easy in J2ME. Anyways its fun programming for Blackberry.

 

Thanks & Regards

Sunil

 

 

 

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

Re: Please Help! Problem in using http for calling url?

BlackBerry code is forward but not backward compatible.  You are coding for a 4.2.2 device, you should be using 4.2.1 or earlier JDE.  I would recomemnd that you stop using 4.6 immediately, it might be bad for your device.
Please use plain text.
Developer
javame_black
Posts: 115
Registered: ‎10-04-2008
My Device: Not Specified

Re: Please Help! Problem in using http for calling url?

Hi,

 

I have tried using WAP 2.0 as shown in the article. But while executing it on device it gives an error as Error while starting application trying to use a Secure API. I think its due to use of ServiceBook while fetching uid for WAP and it may require code signing. Am I correct or not? Regarding testing on simulator its still not working with deviceside=true, would look into that.

 

One more thing I have tested NetworkDiagnostic tool in device and gives error as WLANInfo class not found. That is probably due to the device having Blackberry 4.2.2 version and I am developing with JDE 6.0. If thats the reason then I will have to do the changes as specified in NetworkDiagnostic article and then look into that. Just want to confirm it.

 

I still cant understand why using http is so much pain in Blackberry. When browsing is absolutely is absoutely free from the plan my company has got the device then why cant we use http in third party applications. Anyways still waiting for it to get solved.

 

Thanks & Regards

Sunil

 

 

Regards
Sunil
Please use plain text.
Developer
javame_black
Posts: 115
Registered: ‎10-04-2008
My Device: Not Specified

Re: Please Help! Problem in using http for calling url?

Hi Peter,

 

Thanks a lot for guiding me.

 

I have atlast managed to use http from BlackBerry 8830 using WAP2.0 Gateway. Though rather than using the code I directly looked into the WAP2.0 in the Service Book and appended that UID in the url.

 

For anyone else who wants to use in this way one should go:-

 

Options -> Advanced Options -> Service Book -> WAP2 Transport [WPTCP].

 

Append the UID you found here in the url and your task will be completed.

 

Thanks again Peter 

 

Thanks & Regards

Sunil

 

 

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

Re: Please Help! Problem in using http for calling url?

While hard coding the ConnectionID as you suggest will work on your device with your carrier, it is not really an appropriate solution for most 3rd party developers.

 

Re your previous post:

 

Yes, the ServiceBooks are a secure API and you will need to get a signing key.  it is only $20 with no restrictions on number of Apps you sign.

 

";device=true" works for me in the Simulators.

 

Network Diagnostics will need changes to compile on your level.

 

I think you find that some of the problem is the carriers, who want to be able to control and measure the data you send over their networks, so they can charge you for it.

Please use plain text.
Developer
javame_black
Posts: 115
Registered: ‎10-04-2008
My Device: Not Specified

Re: Please Help! Problem in using http for calling url?

Hi,

 

Yes I understand hardcoding UID in url is not good programming practise. But that application will run in only one blackberry so there wont be any problem.

 

Thanks & Regards

Sunil

Regards
Sunil
Please use plain text.