Has anyone experienced strange behavior while using HttpConnection to connect to networks with J2ME? We think our problem may have something to do with flushing the output stream.
We have been
testing an app that makes an HttpConnection to a PHP page. We send one GET paramater in the URL and then a
string of data using the POST method as follows:
*************************************8
String url = "http://www.webaddress.com/emailServer.php?emailAddr="+emailAddr;
hc = (HttpConnection)Connector.open(url);
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("Content Type", "application/x-www-form-urlencoded");
hc.setRequestProperty("Content-Length", Integer.toString(message.length()));
hc.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0" );
hc.setRequestProperty("Content-Language", "en-US" );
out = new DataOutputStream(hc.openOutputStream());
for(int i=0; i <messageBody.length; i++)
{
out.writeByte(messageBody[i]);
eGauge.setValue(i);
}
out.flush();
out.close();
/*the try, catch, throw code was left out from this sample*/
*************************
The application will work successfully several times but then begin failing indefinately. We noticed that the application is failing when flushing the output stream. It seems to delay for a while and then throws an error.
If anyone has any idea what could be causing such erratic behavior, I'd appreciate your help. Thanks so much!