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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
skylark
Posts: 19
Registered: ‎07-21-2008

Re: HTTP post

Thanks indeed for your patient answers

 

For me, it seems TCP method will work. I will try to implement this into my program and let you know, how it works.

 

As MDS method needs BES installed, i think it's not good to punish our users to install that. 

 

And thanks again SIR!!! 

Please use plain text.
Developer
skylark
Posts: 19
Registered: ‎07-21-2008

Re: HTTP post

[ Edited ]

Hi,

 

I did enterprise activation on my 8100 and tried the following

 

 

try {
byte[] data = message.getBytes();
int dataLength = data.length;
HttpConnection httpConnection = (HttpConnection) Connector.open("https://secure.sample.com/hello.php?p1=23;deviceside=false");
httpConnection.setRequestMethod(HttpConnection.POST);

String itemData=""; int d;
InputStreamReader stream=new InputStreamReader(httpConnection.openInputStream());
int returnCode=httpConnection.getResponseCode();
if(returnCode==HttpConnection.HTTP_OK){
while (true){
d=stream.read();
if (d==-1) break;
else itemData+=((char) d);
}
}
}
catch (Throwable ex) {
ex.printStackTrace();
screen.updateScreen(ex.toString());
}
finally {
httpConnection = null;
httpInput = null;
httpOutput = null;
}

 

When execution is in the line

int returnCode=httpConnection.getResponseCode();

 

an error pop-up says,

An Uncaught exception: Applcation connectionSample is not responding. Process terminated.

 

I think connection has been created. But not getting the response.

 

Please advice me on this.

 

I thank you.

Message Edited by skylark on 07-23-2008 12:05 PM
Message Edited by MSohm on 07-23-2008 01:04 PM
Please use plain text.
Administrator
MSohm
Posts: 12,957
Registered: ‎07-09-2008
My Carrier: Bell

Re: HTTP post

Are you creating the connection in its own thread?  This can happen if you try t open a connection on the main event thread.

 

Support - Application stops responding when opening a connection
Article Number: DB-00159

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/Support...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.
Administrator
MSohm
Posts: 12,957
Registered: ‎07-09-2008
My Carrier: Bell
Please use plain text.
Developer
skylark
Posts: 19
Registered: ‎07-21-2008

Re: HTTP post

Nope,  i have

  1. public class ConnectionExample extends UiApplication
  2. class ConnectionExampleScreen extends MainScreen
  3. class ServerConnection extends Thread
in my ConnectionExample.java

I called the statement

pushScreen(new ConnectionExampleScreen());

in constructor of  ConnectionExample

 

On the button event of ConnectionExampleScreen, i called

 Thread postnameThread = new Thread(new ServerConnection(nameField.getText(), screen));

 

ServerConnection has the follwing in run()

   httpConnection = (HttpConnection) Connector.open(url);screen.updateScreen("Connector.open");

 

 

Please let me know, if i am using the thread properly.

 

I will be here, if you need anything from me.

 

Thanks!!! 

Please use plain text.
Administrator
MSohm
Posts: 12,957
Registered: ‎07-09-2008
My Carrier: Bell

Re: HTTP post

Are you also performing a postnameThread.start() within your button?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.
Administrator
MSohm
Posts: 12,957
Registered: ‎07-09-2008
My Carrier: Bell
Please use plain text.