I am trying to post some values to the server through HttpConnection in Blackberry. I think i am closer to the solution that i am trying for. but once i establish the connection and used the method getResponseCode(). it returns me nothing. i tried with debug option too. but i can't able to find what is returns. the control goes smoothly until that statement. Once that particular statement is reached, then it comes out of the debug mode even. below is the snippet i have attached with, Please let me know your suggestions too.
// MyHttpConnectionService.java
........
........
........
OutputStream _outputStream = _connection.openOutputStream();
try {
int rc = _connection.getResponseCode(); // My control is getting lost here
System.out.println("Response Code :" + rc);
System.out.println("Response Code :" + rc + " if HTTP OK :"
+ (rc == HttpConnection.HTTP_OK));
.........
.........
}catch(Exception e){
e.printStackTrace();
}
It doesn't throws any exception too.
Any help is appreciated.
Looking at the documentation for HTTPConnection, I think you should write your values to _outputStream
and then call outputStream.flush()
.
You mention control being lost when calling _connection.getResposeCode()
, I think that is because this method does several things. From the comments in the example source code:
Getting the response code will open the connection, send the request, and read the HTTP response headers. The headers are stored until requested.
If there are problems reaching the server, it may have to do with your connection string. Are you setting up your connection string correctly?