/* * HttpDemo.java * * Created on 13 ??????? 2546, 16:38 ?. */ import java.io.*; import javax.microedition.io.*; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * @author sup98 * @version */ public class HttpDemo extends MIDlet { private Display display; String url = "http://localhost/ASPDate.php"; public HttpDemo() { display = Display.getDisplay(this); } /** * Start up the Hello MIDlet by creating the TextBox and associating * the exit command and listener. */ public void startApp() { try{ invokeASP(url); }catch(IOException e){ System.out.println("IOException " + e); e.printStackTrace(); } } /** * Pause is a no-op since there are no background activities or * record stores that need to be closed. */ public void pauseApp() { } /** * Destroy must cleanup everything not handled by the garbage collector. * In this case there is nothing to cleanup. */ public void destroyApp(boolean unconditional) { } void invokeASP(String url) throws IOException{ HttpConnection c = null; InputStream is = null; StringBuffer b = new StringBuffer(); TextBox t = null; try{ c = (HttpConnection)Connector.open(url); c.setRequestMethod(HttpConnection.GET); c.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT"); c.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0"); c.setRequestProperty("Content-Language", "en-US"); is = c.openDataInputStream(); int ch; while((ch = is.read())!= -1){ b.append((char) ch); //System.out.println((char) ch); } t = new TextBox("First HTTP Demo", b.toString(), 1024, 0); }finally{ if(is != null){ is.close(); } if(c != null){ c.close(); } } display.setCurrent(t); } }