I've read a lot posts on the web, but I haven't found solution.
I've developed a BlackBerry App ( SDK 5 ) that's using HttpConnection
to get/set data from server.
I tried to connect via Wireless and G2/G3 connection.
In both cases Application works fine for some time and then suddenly internet connection breaks (sometimes in the middle of the loading data from the server). After that happens Application doesn't work and I also can't go to any web page (in BB Browser). It looks like BB disables internet.
When I try it in BB Browser I get the following message:
Unable to connect to the Internet please try again later. If the problem persists please contact your service provider
The only way to get the internet back is to go to settings and disable WiFi and then re-Enable it again. After that it works, but again for some time.
It never breaks at the same point.
Here is the code that I'm using to get data from the server:
String urlPath = "http://www.mysite.com/api/?debug=true";
//debug is my variable on the site, it's not necessary
if(DeviceInfo.isSimulator()){
urlPath += ";deviceside=true";
} else {
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
urlPath += ";interface=wifi";
}else{
urlPath += ";deviceside=true";
}
}
HttpConnection httpConn = (HttpConnection) Connector.open( urlPath );
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
httpConn.setRequestProperty("Content-Language", "en-US");
httpConn.setRequestProperty("Connection", "close");
OutputStream os = httpConn.openOutputStream();
os.write(temp1.getBytes());
os.flush();
os.close();
StringBuffer sb = new StringBuffer();
DataInputStream is = httpConn.openDataInputStream();
int chr;
while ((chr = is.read()) != -1) {
sb.append((char) chr);
}
String response = new String(sb.toString().getBytes(), "UTF-8");
What am I doing wrong?
Is there a way to fix this and keep the connection stable and responsive?
Thanks.