BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 08-28-2009, 02:26 AM   #1 (permalink)
Knows Where the Search Button Is
Join Date: Aug 2009
Model: 9000
Carrier: T-System
Posts: 23
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default network connection problem

Please Login to Remove!

Hi Myself Durg

I am newbie in BlackBerry development. I want to connect my application from internet. My code is

HttpConnection code:

//import java.util.*;

public class HttpCommunicationHandler


* This method retrieves the data from the server using HTTP POST.

public String getDataFromServerThroughPost(String getUrl, String urlData)
HttpConnection httpConn = null;
InputStream is = null;
OutputStream out = null;
String httpUrl = getUrl;
String paramsToBeSend = urlData;
String dataRead = "";

try {
httpConn = (HttpConnection);
httpConn.setRequestProperty("Content-Length", Integer.toString(paramsToBeSend.length()));
out = httpConn.openOutputStream();
if (out != null)
if ((httpConn.getResponseCode() == HttpConnection.HTTP_OK))
int length = (int) httpConn.getLength();
is = httpConn.openInputStream();
if (length == -1)
int chunkSize = 1024;
byte[] data = new byte[chunkSize];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int dataSizeRead = 0;// size of data read from input stream.
// keeps track of total size of data read upto now.
int totalDataSizeRead = 0;
while ((dataSizeRead = != -1)

baos.write(data, 0, dataSizeRead);
dataRead = new String(baos.toByteArray());

else {
byte[] data = new byte[length];
// try to read all the bytes returned from the server.;
// dis.readFully(data);
dataRead = new String(data);
//if (data != null)
//data = null;


else {
// UIController.showErrorAlert("Network Error",
// "Error in communicating with the server.", d);
//System.out.println("Network Error","Error in communicating with the server.");

catch (IOException e)
String str ="hello";

//System.out.println("Network Error","Error in communicating with the server.", "OK", null);


// Since only limited number of network objects can be in open state
// it is necessary to clean them up as soon as we are done with them.
// Networking done. Clean up the network objects
finally {
if (is != null)

catch (IOException e)

if (httpConn != null)
catch (IOException e)
//System.out.println("Exception occured " + t.toString());
return dataRead;

and I use this class in to my loginclass. I am sending the login and password and match after that want to print the success message.

LoginScreen code: want to generate action on click login button

String datafrom = "";
HttpCommunicationHandler http = new HttpCommunicationHandler();
String getUrl =" my url";
String urlData ="?requestStr=<UserInfo><UserID>ravi</UserID><Password>kant</Password><LoginDate></LoginDate><IPAddress></IPAddress></UserInfo>";
datafrom = http.getDataFromServerThroughPost(getUrl,urlData);
System.out.println("value of datafrom"+datafrom);
catch(Throwable t){

When I click on the login button my app freeze.Please help me . its very urgent. Is there any permisson to set for network connection?

Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Reconditioned Windsor Commodore 20 Carpet Extractor
Reconditioned Windsor Commodore 20 Carpet Extractor pictureWindsor Commodore Duo
Windsor Commodore Duo pictureJelenko commodore VPF porcelain furnace
Jelenko commodore VPF porcelain furnace pictureWINDSOR Commodore CMD Carpet Extractor Cleaning Machine 0541 Hours WORKING
WINDSOR Commodore CMD Carpet Extractor Cleaning Machine 0541 Hours WORKING pictureComfort Products 60-5800T Commodore II Oversize Leather Chair with Adjust... New
Comfort Products 60-5800T Commodore II Oversize Leather Chair with Adjust... New picture

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.