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);
เนื่องจากตอนนี้ต้องการ code ที่ connect ระว่างมือถือ กับ server โดยมีการใช้ web service เข้ามาเกี่ยวข้อง เพราะกำลังทำระบบที่ใช้ หลักการ web service บนมือถือผ่านเครือข่าย GPRS คืออยากได้ code ที่ชเอมกับมือถือได้จริงๆ ค่ะ ใครรู้ช่วยหน่อยนะคะ