Try this:
PHP Code:
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HttpReader extends MIDlet implements CommandListener, Runnable {
private static final Command cmdGET = new Command("GET", Command.SCREEN, 1);
private static final Command cmdEXIT = new Command("Exit", Command.EXIT, 1);
private static final String DOCUMENT_URL = "http://www.google.com/";
private Form frm;
private StringItem status;
public void startApp() {
Display disp = Display.getDisplay(this);
frm = new Form("HttpReader");
frm.addCommand(cmdEXIT);
frm.addCommand(cmdGET);
frm.setCommandListener(this);
status = new StringItem(null, "Ready");
frm.append(status);
disp.setCurrent(frm);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
private void setStatus(String s) {
status.setText(s);
}
// implementation: CommandListener
public void commandAction(Command cmd, Displayable disp) {
if (cmd == cmdEXIT) {
destroyApp(false);
notifyDestroyed();
} else if (cmd == cmdGET) {
frm.removeCommand(cmdGET);
frm.removeCommand(cmdEXIT);
(new Thread(this)).start();
}
}
// implementation: Runnable
public void run() {
try {
setStatus("Connecting...");
HttpConnection httpc = (HttpConnection) Connector.open(DOCUMENT_URL);
try {
httpc.setRequestMethod(HttpConnection.GET);
int code = httpc.getResponseCode();
if (code != HttpConnection.HTTP_OK) {
throw new Exception("HTTP code: " + code);
}
String type = httpc.getType();
int length = (int) httpc.getLength();
if (length >= 0) {
byte[] ao = new byte[length];
DataInputStream din = httpc.openDataInputStream();
try {
din.readFully(ao);
} finally {
din.close();
}
if (type.startsWith("text/")) {
frm.append(new String(ao));
} else if (type.startsWith("image/")) {
frm.append(Image.createImage(ao, 0, length));
} else {
frm.append("Can't handle type: " + type);
}
} else {
setStatus("no length");
}
} finally {
httpc.close();
}
setStatus("Complete.");
} catch (Exception e) {
setStatus("Error: " + e);
} finally {
frm.addCommand(cmdEXIT);
}
}
}
Graham.