Hello,
we have developed the MIDP1.0/CLDC1.0 midlet communicating
with the server via http connections. But we have serious troubles
with any other phones then Nokia ones because it does not communicate
at all when ran on Samsung X100, Motorola V500, T722i, S&E T610,
emulators are still OK. We have tried ‘several’ URL formats as http://www.yahoo.com/
or http://216.109.117.110:80/robots.txt but no chance to get it running.
Do you know some MIDP1.0/CLDC1.0 aps communication well? Where could be the problem?
See the code.
Best Regards
Jan Kopinec
public class HttpConnect {
public static HttpConnection c = null;
public static InputStream is = null;
public static OutputStream os = null;
public static String connect(GigaSlot midlet, String url, String stream) throws IOException {
try {
c = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
c.setRequestMethod(HttpConnection.POST);
//c.setRequestProperty(“User-Agent”, “Profile/MIDP-1.0 Configuration/CLDC-1.0”);
c.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”);
byte [] dat = stream.getBytes();
os = c.openOutputStream();
os.write(dat);
os.close();
os = null;
System.gc();
is = c.openInputStream();
String s = null;
int len = (int) c.getLength();
if (len > 0) {
byte[] data = new byte[len];
int actual = is.read(data);
s = new String(data);
data = null;
} else {
StringBuffer buf = new StringBuffer();
int ch;
while (((ch = is.read()) != -1) && midlet.connect) {
if(!midlet.connect) {
try {
if (is != null) {
is.close();
is = null;
}
if (c != null) {
c.close();
c = null;
}
} catch(IOException e) { }
}
buf.append((char) ch);
}
s = buf.toString();
buf = null;
System.gc();
}
if(midlet.connect) {
return s;
} else {
return “”;
}
} finally {
if (is != null) {
is.close();
is = null;
}
if (c != null) {
c.close();
c = null;
}
}
}